Write Python. Understand every error.

Open the editor

Error guide · AttributeError

AttributeError: 'NoneType' object has no attribute 'append'

A variable holds None, which means nothing, so the method you called does not exist.

Example

numbers = [3, 1, 2]
numbers = numbers.sort()
numbers.append(4)

What Python says

AttributeError: 'NoneType' object has no attribute 'append'

As printed by Python 3.12. Other versions may word it slightly differently.

Try this code in Py-CRAFT

Why it happens

sort(), append(), reverse() and similar methods change the list in place and return None. Writing numbers = numbers.sort() replaces your list with None, so the next method call fails. The same thing happens when a function you wrote has no return and you use its result.

How to fix it

numbers = [3, 1, 2]
numbers.sort()
numbers.append(4)
print(numbers)

Output: [1, 2, 3, 4]

Tips

Learn the ideas behind it

Other common errors

Share this page: