Skip to content
Advertisement

Appending turns my list to NoneType [duplicate]

In Python Shell, I entered:

JavaScript

and got

JavaScript

but when I tried:

JavaScript

and got

JavaScript

Does anyone know what’s going on? How can I fix/get around it?

Advertisement

Answer

list.append is a method that modifies the existing list. It doesn’t return a new list — it returns None, like most methods that modify the list. Simply do aList.append('e') and your list will get the element appended.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement