{ }codelper

Error Messages › Python

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))
When you run it
15
Traceback (most recent call last):
  File "main.py", line 6, in <module>
TypeError: 'int' object is not callable

Edit and run it →

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))
Output
15
15

Edit and run it →

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)
When you run it
Traceback (most recent call last):
  File "main.py", line 2, in <module>
TypeError: 'int' object is not callable

Edit and run it →

Fixed code

You always have to write * to multiply.

n = 10print(n * (n + 1) // 2)
Output
55

Edit and run it →

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))
When you run it
Traceback (most recent call last):
  File "main.py", line 2, in <module>
TypeError: 'list' object is not callable

Edit and run it →

Fixed code

Change the parentheses to square brackets.

a = [10, 20, 30]print(a[0])
Output
10

Edit and run it →

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))
When you run it
6
Traceback (most recent call last):
  File "main.py", line 6, in <module>
TypeError: 'int' object is not callable

Edit and run it →

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))
Output
6
20

Edit and run it →

What to check when you see this error

  1. On the line where the error happened (the number after line), find the name right before the (.
  2. 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.
  3. Check that a * is not missing between a number and a parenthesis, or between two parentheses.
  4. If you are getting an item from a list, string or dictionary, change the parentheses to square brackets.

Practice problems

See also