fuckingpython.lol

Python errors › AttributeError

AttributeError: 'list' object has no attribute

Updated

The Python error "'list' object has no attribute" means a method from another language, like push, or a str method on a list. Python 3.15 names the fix.

What you see

main.py
items = [1, 2, 3]
items.push(4)
Python 3.15 prints
Traceback (most recent call last):
  File "/home/me/project/main.py", line 2, in <module>
    items.push(4)
    ^^^^^^^^^^
AttributeError: 'list' object has no attribute 'push'. Did you mean '.append'?

What it means

Lists do not have a method called push. That is JavaScript's name; in Python the method is append. Python 3.15 knows the common method names from JavaScript, Java, Ruby and C# and suggests the Python one, as above.

The other frequent version of this error is a list where you expected something else, such as a string, a dict or a single object.

Why it happens

These are the names people reach for most often, with the Python equivalent:

  • push or add: use items.append(x), or items.extend(more) for several. add is the method of a set.
  • length, size or count() for the length: use len(items). items.count(x) exists, but counts occurrences of x.
  • includes or contains: use x in items.
  • indexOf: use items.index(x), which raises ValueError when x is not there.
  • split, lower, strip or replace: these are string methods. You have a list, often from an earlier split() or readlines(); loop over it, or join it first.
  • get, keys or items: these belong to a dict. JSON that you expected to be an object may be a list of objects.

How to fix it

Use the Python method, or check what the variable holds:

items.append(4)
print(type(items), items[:3])

For string methods on a list of strings, apply them to each item:

lines = [line.strip() for line in lines]

Example: a JavaScript string method

main.py
name = "ada"
print(name.toUpperCase())
Python 3.15 prints
Traceback (most recent call last):
  File "/home/me/project/main.py", line 2, in <module>
    print(name.toUpperCase())
          ^^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'toUpperCase'. Did you mean '.upper'?
PythonPrints
3.9–3.14AttributeError: 'str' object has no attribute 'toUpperCase'
3.15AttributeError: 'str' object has no attribute 'toUpperCase'. Did you mean '.upper'?

Run on CPython 3.9.6, 3.10.22, 3.11.17, 3.12.15, 3.13.17, 3.14.9 and 3.15.1, on October 25, 2026.

Example: a Java map method on a dict

main.py
ages = {}
ages.put("ada", 36)
Python 3.15 prints
Traceback (most recent call last):
  File "/home/me/project/main.py", line 2, in <module>
    ages.put("ada", 36)
    ^^^^^^^^
AttributeError: 'dict' object has no attribute 'put'. Use d[k] = v.
PythonPrints
3.9–3.14AttributeError: 'dict' object has no attribute 'put'
3.15AttributeError: 'dict' object has no attribute 'put'. Use d[k] = v.

Run on CPython 3.9.6, 3.10.22, 3.11.17, 3.12.15, 3.13.17, 3.14.9 and 3.15.1, on October 25, 2026.

How each Python version words it

PythonPrints
3.9–3.14AttributeError: 'list' object has no attribute 'push'
3.15AttributeError: 'list' object has no attribute 'push'. Did you mean '.append'?

Run on CPython 3.9.6, 3.10.22, 3.11.17, 3.12.15, 3.13.17, 3.14.9 and 3.15.1, on October 25, 2026.

Up to 3.14 these examples end at "has no attribute 'push'". 3.15 adds a hint: "Did you mean '.append'?", "Did you mean '.upper'?", and for the dict, "Use d[k] = v." The hints work on subclasses of the builtin types as well.

Questions

Why is there no push alias?

Python has one name for each operation on its builtin types. append adds one item to the end; insert(0, x) adds at the front.

How do I tell a list from a string when debugging?

print(type(x)) names the type, and print(repr(x)) shows the value with its brackets or quotes.

Sources

Read on October 25, 2026.