AttributeError: 'str' object has no attribute 'append'
You’re calling a method or accessing a property that doesn’t exist on that type.
Fix 1: Check the type
# ❌ Strings don't have .append()
name = "Alice"
name.append(" Smith") # AttributeError!
# ✅ Use the right method for the type
name = "Alice"
name = name + " Smith" # Strings use concatenation
# Lists have .append()
items = ["Alice"]
items.append("Bob")
Fix 2: Check for typos
# ❌ Typo
my_list.apend("item")
# ✅ Correct spelling
my_list.append("item")
Fix 3: Variable is None
# ❌ Function returned None
result = my_list.sort() # .sort() returns None!
result.append("item") # AttributeError!
# ✅ .sort() modifies in place
my_list.sort()
my_list.append("item")
Common methods that return None: .sort(), .append(), .extend(), .reverse(), .clear().
Fix 4: Wrong import or module
# ❌ Imported the module, not the class
import json
data = json.loads(text)
data.loads(more_text) # dict has no .loads()!
# ✅ json.loads() is on the module, not the result
more_data = json.loads(more_text)
Debugging tip
# Check what attributes exist
print(type(my_var))
print(dir(my_var))
See also: Python cheat sheet | Python NoneType not subscriptable fix