AttributeError: 'list' object has no attribute
AttributeError: 'list' object has no attribute in Python means you called a method on a list that belongs to another type, such as .split(), .strip(), .lower() (strings) or .keys() (dictionaries).
How do I fix AttributeError: 'list' object has no attribute?
To fix AttributeError: 'list' object has no attribute in Python, locate the line causing the error and check the values right before it runs. Most occurrences happen because of calling a string method on a list of strings. Apply a defensive check or safe fallback, make sure collections or objects exist before access, and verify return values from upstream functions.
What does AttributeError: 'list' object has no attribute mean?
Python lists have methods like .append(), .pop(), and .extend(), but do not have string, dictionary, or set methods. This error often surfaces when a function returns a list of items and you accidentally call a string method on the entire list instead of iterating over it.
Why does AttributeError: 'list' object has no attribute happen?
1. Calling a string method on a list of strings
split() or lower() must be called on individual strings, not the containing list.
Breaks
words = ["HELLO", "WORLD"]
clean = words.lower()Works
words = ["HELLO", "WORLD"]
clean = [w.lower() for w in words]2. Using JavaScript's .push() instead of Python's .append()
Python lists use .append(item), not .push(item).
Breaks
numbers = [1, 2, 3]
numbers.push(4)Works
numbers = [1, 2, 3]
numbers.append(4)3. Calling .keys() or .values() on a list
Only dictionaries have keys() and values().
Breaks
rows = [{"id": 1}, {"id": 2}]
ids = rows.keys()Works
rows = [{"id": 1}, {"id": 2}]
ids = [r["id"] for r in rows]How to find it in your own code
Check the type of the variable with type(x). If it is a list of strings or dictionaries, use a list comprehension or loop to apply the method to each item individually.
Try it: fix this bug
easyformat_price(5) crashes: TypeError: can only concatenate str (not "int") to str.
def format_price(amount):
return "$" + amountMore challenges with this error
Each of these challenges runs into this error or pattern. Find the bug and fix it in your browser โ no install, no account needed.
Still not sure why yours breaks?
Paste it into the visualizer and watch it run line by line, with every variable at every step. Free, and it runs in your browser.