Write Python. Understand every error.

Open the editor

Error guide · AttributeError

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

You used a list method on text.

Example

word = "cat"
word.append("s")

What Python says

AttributeError: 'str' 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

append belongs to lists. Strings cannot be changed in place, so they have no such method. To add text, build a new string with +. The error message always names the type of the value and the missing method, which tells you what to look up.

How to fix it

word = "cat"
word = word + "s"
print(word)

Output: cats

Tips

Learn the ideas behind it

Other common errors

Share this page: