TypeError: 'list' object is not callable
You put ( ) after something that is not a function. Usually a built-in name like list or str has been overwritten by your own variable.
What it means
Calling means ( ). Python is telling you the thing before the parentheses is a list (or str, int, dict) — data, not a function. The same message appears as 'str' object is not callable, 'int' object is not callable and so on; the type in quotes is what the name actually holds right now.
Common causes
1. Shadowing a built-in
Naming a variable list, str, sum or max replaces the built-in for the rest of that scope. The crash comes later, where you call the built-in.
Breaks
list = [3, 1, 2]
unique = list(set(items))Works
numbers = [3, 1, 2]
unique = list(set(items))2. Parentheses instead of square brackets
items(0) calls items. items[0] indexes it.
Breaks
first = items(0)Works
first = items[0]3. An attribute with the same name as a method
Assigning self.total = 0 in __init__ hides a method called total().
Breaks
class Cart:
def __init__(self):
self.total = 0
def total(self):
return sum(self.prices)Works
class Cart:
def __init__(self):
self.running_total = 0
def total(self):
return sum(self.prices)How to find it in your own code
Search your file for `name =` where name is the thing being called. If you shadowed a built-in, rename your variable. In an interactive session or notebook, the shadowing survives until you restart — `del list` restores the built-in.
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.