Write Python. Understand every error.

Open the editor

Error guide · AttributeError

AttributeError: object has no attribute

You used a method or attribute that this kind of value does not have.

Example

names = ["Riya", "Arjun"]
names.push("Meera")
print(names)

What Python says

AttributeError: 'list' object has no attribute 'push'

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

Try this code in Py-CRAFT

Why it happens

Each type has its own methods. Lists use append, not push (that is JavaScript). The error also appears with a spelling mistake in a method name, or when a variable holds a different type than you think, such as None.

How to fix it

names = ["Riya", "Arjun"]
names.append("Meera")
print(names)

Output: ['Riya', 'Arjun', 'Meera']

Tips

Learn the ideas behind it

Other common errors

Share this page: