ShareYourGroupShareYourGroupPython

AttributeError: object has no attribute

An AttributeError appears when you put a dot after a value and ask for something that kind of value does not have. Methods and properties reached with a dot are called attributes. A string has upper. A list has append. A list has no upper, and asking for it raises this error.

names = ["asha", "ravi"]
print(names.upper())

What Python says

Traceback (most recent call last):
  File "example.py", line 2, in <module>
    print(names.upper())
          ^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'upper'

The message has two useful parts: the type of the value on the left of the dot, and the name that was not found.

Cause 1: the value is not the type you think

In the example above, upper belongs to strings and names is a list. Apply the method to each string inside the list.

names = ["asha", "ravi"]
print([n.upper() for n in names])

Output

['ASHA', 'RAVI']

The opposite mix-up is just as common.

word = "asha"
word.append("!")

What Python says

Traceback (most recent call last):
  File "example.py", line 2, in <module>
    word.append("!")
    ^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'append'

Strings have no append, because they cannot be changed. Build a new string with word + "!".

When in doubt, print the type: print(type(names)).

Cause 2: the value is None

cart = ["rice", "dal"]
cart = cart.append("sugar")
cart.append("tea")

What Python says

Traceback (most recent call last):
  File "example.py", line 3, in <module>
    cart.append("tea")
    ^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'append'

A message that mentions 'NoneType' means the thing before the dot is None. Here, append changed the list and returned None, and the assignment stored that None back into cart. List methods that change the list in place, such as append, sort, reverse and remove, all return None. Call them on their own line and do not assign the result.

None also turns up when a function has no return on some path, and when get or a search finds nothing.

Cause 3: a spelling mistake in the method name

name = "asha"
print(name.uper())

What Python says

Traceback (most recent call last):
  File "example.py", line 2, in <module>
    print(name.uper())
          ^^^^^^^^^
AttributeError: 'str' object has no attribute 'uper'. Did you mean: 'upper'?

Python often suggests the right name. To see what a value offers, use dir.

print([m for m in dir("text") if m.startswith("up")])

Output

['upper']

Cause 4: a method that belongs to another type

Beginners often try text.length or my_list.size(), as some other languages have. In Python, length is always the function len(...). Likewise, there is no list.add; the method is append. Sets use add, and dictionaries use neither.

basket = {"apple", "kiwi"}
basket.append("fig")

What Python says

Traceback (most recent call last):
  File "example.py", line 2, in <module>
    basket.append("fig")
    ^^^^^^^^^^^^^
AttributeError: 'set' object has no attribute 'append'

Cause 5: your file has the name of a module

# saved as random.py
import random
print(random.randint(1, 6))

If your own program is saved as random.py, the line import random loads your file, not Python's module. Your file has no randint, so you get an AttributeError saying the module has no such attribute. Rename your file to something else, such as dice_game.py, and delete any folder named __pycache__ beside it.

Cause 6: an attribute never set in your own class

class Student:
    def __init__(self, name):
        name = name

s = Student("Asha")
print(s.name)

What Python says

Traceback (most recent call last):
  File "example.py", line 6, in <module>
    print(s.name)
          ^^^^^^
AttributeError: 'Student' object has no attribute 'name'

Inside __init__, the value must be stored on the object with self.name = name. Without self, it was only a local variable and vanished.

Steps to fix

  1. Read the type named in the message. Is that the type you expected the variable to hold?
  2. If the type is NoneType, find where the variable was assigned and look for a method or function that returns nothing.
  3. If the type is right, check the spelling of the attribute.
  4. If the message is about a module, check the name of your own file.

Other error messages

Examples on this page were run with Python 3.14 on 12 November 2026. The output shown is the real output.

This is an independent learning site. It is not connected with or approved by the Python Software Foundation. "Python" is a trademark of the Python Software Foundation and is used here only to name the language.