Python TypeError: 'int' object is not callable
TypeError: 'int' object is not callable
Putting parentheses after a name, as in name(...), means you are calling a function. If that name holds a number, a string or a list instead of a function, it cannot be called, and you get this error. The word in quotes ('int', 'str', 'list') is the type of the value that was in front of the parentheses.
Cause 1. You used a function name as a variable name
This is the most common cause. The moment you write sum = 0, sum is no longer the adding function but a variable that points to the number 0. Calling sum(a) after that means calling a number.
The same thing happens if you use str, list, max, min, len, input or print as a variable name. Writing str(5) after str = input() gives 'str' object is not callable.
Wrong code
a = [3, 5, 7]sum = 0for x in a: sum = sum + xprint(sum)print(sum(a))15 Traceback (most recent call last): File "main.py", line 6, in <module> TypeError: 'int' object is not callable
Fixed code
Rename the variable so it does not clash with a function: for example total, text or nums.
a = [3, 5, 7]total = 0for x in a: total = total + xprint(total)print(sum(a))15 15
Cause 2. You left out the multiplication sign
In math, n(n + 1) is a multiplication. In Python it means "call a function named n".
Wrong code
n = 10print(n(n + 1) // 2)Traceback (most recent call last): File "main.py", line 2, in <module> TypeError: 'int' object is not callable
Fixed code
You always have to write * to multiply.
Cause 3. You used parentheses to get an item from a list
To get a value out of a list or a string, you use square brackets. Writing a(0) gives 'list' object is not callable.
Wrong code
a = [10, 20, 30]print(a(0))Traceback (most recent call last): File "main.py", line 2, in <module> TypeError: 'list' object is not callable
Fixed code
Change the parentheses to square brackets.
Cause 4. You made a variable with the same name as your function
The same goes for functions you write yourself. If you store a function's result in a variable with the same name as the function, that name now points to the result. The second call fails.
Wrong code
def area(w, h): return w * h area = area(2, 3)print(area)print(area(4, 5))6 Traceback (most recent call last): File "main.py", line 6, in <module> TypeError: 'int' object is not callable
Fixed code
Give the variable that holds the result a different name.
def area(w, h): return w * h small = area(2, 3)print(small)print(area(4, 5))6 20
What to check when you see this error
- On the line where the error happened (the number after
line), find the name right before the(. - Look for a place in your code where that name is used as a variable, as in
name = .... If there is one, rename the variable. - Check that a
*is not missing between a number and a parenthesis, or between two parentheses. - If you are getting an item from a list, string or dictionary, change the parentheses to square brackets.
Practice problems
See also
- Python 'int' object is not subscriptable
- Python missing 1 required positional argument
- Python NameError: name 'x' is not defined
- Syntax: Python Slicing: [start:stop:step] Explained
- Syntax: Python print(): Output with sep and end
- Learn it step by step: Python Functions
- All Python error messages
- Online Python interpreter