AttributeError: 'list' object has no attribute (Fix)
This error happens when Python sees a list, but your code tries to use a method or attribute that lists do not have.
A common example is using a string method like lower() on a list:
my_list = ["A", "B", "C"]
my_list.lower()
That fails because lower() works on strings, not on lists.
Quick fix
my_list = ["a", "b", "c"]
# Wrong: lists do not have string methods like lower()
# my_list.lower()
# Fix 1: use a list method
my_list.append("d")
# Fix 2: apply the string method to each item
lowered = [item.lower() for item in my_list]
print(lowered)
Output:
['a', 'b', 'c', 'd']
This error usually means you are treating a list like a string, dictionary, or another object type.
What this error means
Python is telling you:
- It found a list object
- Your code tried to use an attribute or method that lists do not have
- An attribute can be a value or a method attached to an object
- Lists have methods like
append(), but they do not have methods likelower()
For example:
words = ["Hello", "World"]
words.lower()
This raises:
AttributeError: 'list' object has no attribute 'lower'
Why this happens
This error often appears when:
- You expected a string but actually have a list
- You expected a dictionary but actually have a list
- You used a method from another type by mistake
- A function returned a list and you forgot to check the result
- Your variable name does not make the data type clear
If you are not sure what type a variable contains, check it with type().
Common examples that cause the error
Here are some common mistakes.
Calling string methods on a list
names = ["ALICE", "BOB"]
print(names.lower())
lower() is a string method, so this fails.
Calling dictionary methods on a list
items = ["a", "b", "c"]
print(items.keys())
keys() is for dictionaries, not lists.
Calling items() on a list
data = [1, 2, 3]
print(data.items())
Again, items() belongs to dictionaries.
Using dot notation when you meant indexing
letters = ["a", "b", "c"]
print(letters.upper())
If you wanted the first item and then the string method, use indexing:
letters = ["a", "b", "c"]
print(letters[0].upper())
Output:
A
Assuming all objects support the same methods
Different Python types have different methods.
- Strings have methods like
lower()andsplit() - Dictionaries have methods like
keys()anditems() - Lists have methods like
append()andpop()
If you need a refresher, see Python lists explained.
How to fix it
Use these steps to fix the error.
- Check what type the variable really is with
type() - Print the variable before the failing line
- Use a real list method such as
append(),extend(),pop(), orsort() - If you need one item, access it first with an index
- If each item is a string, loop through the list or use a list comprehension
- Rename variables so the data type is easier to recognize
Fix 1: Check the type first
value = ["One", "Two", "Three"]
print(value)
print(type(value))
Output:
['One', 'Two', 'Three']
<class 'list'>
Now you know the variable is a list.
Fix 2: Use a real list method
If you wanted to add an item, use a list method like append():
numbers = [1, 2, 3]
numbers.append(4)
print(numbers)
Output:
[1, 2, 3, 4]
Fix 3: Access one item first
If the list contains strings and you want to use a string method, get one string from the list first:
words = ["HELLO", "WORLD"]
print(words[0].lower())
Output:
hello
Fix 4: Apply the method to every item
If you want to change all strings in the list, loop through it or use a list comprehension:
words = ["HELLO", "WORLD"]
lowered_words = [word.lower() for word in words]
print(lowered_words)
Output:
['hello', 'world']
If you need help with loops, see how to loop through a list in Python.
Step-by-step debugging checklist
When you see this error, try this process:
- Read the exact method name in the error message
- Find the variable before the dot
- Print the variable and its type
- Decide whether you need the whole list or one item from it
- Replace the wrong method with the correct list method or item method
Useful debugging commands:
my_list = ["Hello", "World"]
print(my_list)
print(type(my_list))
print(dir(my_list))
print(my_list[0])
print(type(my_list[0]))
What these do:
print(my_list)shows the current valueprint(type(my_list))shows that it is a listprint(dir(my_list))shows available list attributes and methodsprint(my_list[0])shows the first itemprint(type(my_list[0]))shows the type of that item
When you meant to use a string method
This is one of the most common versions of the error.
Methods like these are string methods:
lower()upper()strip()replace()split()
Use the method on one string item
fruits = ["Apple", "Banana", "Cherry"]
print(fruits[1].lower())
Output:
banana
Use the method on every string in the list
fruits = [" Apple ", " Banana ", " Cherry "]
cleaned = [fruit.strip().lower() for fruit in fruits]
print(cleaned)
Output:
['apple', 'banana', 'cherry']
If you meant to split a single string, not a list, see how to split a string in Python.
Related errors to compare
Some similar errors come from the same basic problem: the object is not the type you expected.
- AttributeError in Python: causes and fixes for the general pattern
- AttributeError:
'str' object has no attributewhen the object is a string - AttributeError:
'NoneType' object has no attributewhen a variable isNone TypeError: list indices must be integers or sliceswhen list access syntax is wrong
Common mistakes
These are the most common causes of this error:
- Using string methods on a list
- Using dictionary methods on a list
- Confusing one list item with the whole list
- Getting an unexpected function return value
- Reassigning a variable so its type changes
Example of variable reassignment changing the type:
data = "hello"
print(data.upper())
data = ["hello", "world"]
print(data.upper())
The first upper() works because data is a string. The second fails because data is now a list.
FAQ
Why does Python say a list has no attribute?
Because you called a method or attribute that is not defined for list objects.
How do I know what methods a list has?
Use dir(your_list) or check list method reference pages such as append(), extend(), pop(), and sort().
Why does lower() fail on a list?
lower() is a string method, not a list method. Use it on one string item or on each item in the list.
How do I fix this if my list contains strings?
Use indexing for one item, like my_list[0].lower(), or use a loop or list comprehension for all items.
See also
- AttributeError in Python: causes and fixes
- Python lists explained
- Python list
append()method - Python
type()function explained - How to loop through a list in Python
Check the object type first. Then choose the correct list method or work with a single item from the list.