All Python errors
AttributeError in Python: no such method or attribute
AttributeError means the value before the dot has no method or attribute with that name. To fix it, check the spelling of the method and make sure the value really has the type you expect.
Code with the error
word = "python"
print(word.shout())
Error message (Python 3.12, last line)
Corrected code
word = "python"
print(word.upper())
Output
PYTHON
Common causes
- A method name is misspelled or invented.
- A list method is called on a string, or the other way round.
- The value is None, often because a method such as list.sort() returns nothing.
- Wrong letter case: Upper() instead of upper().
Practise in the course
Lesson: String MethodsFrequently asked questions
Why do I see “NoneType object has no attribute”?
The variable holds None. Find where it got its value: some methods change a list in place and return None.
How do I know which methods a string has?
See the lesson on string methods or the official Python documentation for str.