Append function usage

https://app.dataquest.io/m/1018/lists/8/concatenate-lists

list1=['a','b']
list2=['c','d'] 
print(list1+list2)
print(list1.append(list2))
print(list1.append('z'))

Why do I get NoneType error for 2nd and 3rd print statements, please.

Hey.

That happens because list.append doesn’t return anything. It modifies the objects in place. Review the following example.

>>> my_list = ["Epstein", "didn't" "kill", "himself"]
>>> print(my_list.append("."))
None
>>> print(my_list)
['Epstein', "didn'tkill", 'himself', '.']

I hope this helps.

Thank you! Per your note, I re-wrote the function as:

def concatenate(list1,list2):
    list1.append(list2)
    return list1
    print(list1)

Error message: Function concatenate did not return the expected value

On a separate note, I am unable to create a post. I get the error - ‘Internal Server Error’

@nityesh Can you please help out here?

You’re not concatenating the lists, you’re adding the second one as an element of the first.

Wow! This makes sense. Thank you! Would not have been able to figure it out myself.

1 Like

Yes :frowning:
What context would you like me to provide please.
I tried pasting the content here, but get the same error: Internal Server Error