TryBugHunt

TypeError: 'int' object is not callable

TypeError: 'int' object is not callable in Python means you put brackets () after something that is a number, so Python tried to run the number like a function. Most often a variable called sum, max, len or round has replaced the built-in function.

PythonPattern: Type errors

How do I fix TypeError: 'int' object is not callable?

TypeError: 'int' object is not callable means you put () after a name that holds a number. Most often a variable called sum, max, len or round has replaced the built-in function, for example sum = 0. Rename that variable to something like total. A missing * in maths, like 2(x + 1), also causes it.

  1. 1. Find the name before (On the failing line, look at the name just before the bracket. print(type(name)) will show <class 'int'>.
  2. 2. Search for the assignmentSearch upward for where that name was set to a number, such as sum = 0, and rename it.
  3. 3. Write every *In formulas, write 2 * (x + 1), never 2(x + 1). Python reads the second one as calling 2.

What does TypeError: 'int' object is not callable mean?

In Python, name() means "call the function stored in name". Built-in functions like sum and max are just names, and you are allowed to reuse them. If you write sum = 0, the name sum now holds the number 0, and the next sum(...) tries to call 0. A missing * in maths, like 2(x + 1), causes the same error.

Why does TypeError: 'int' object is not callable happen?

1. A variable named after a built-in function

After sum = 0, sum is a number, not the function anymore.

Breaks

sum = 0
for n in [1, 2, 3]:
    sum += n
print(sum([4, 5]))

Works

total = 0
for n in [1, 2, 3]:
    total += n
print(sum([4, 5]))

2. A missing * in a formula

Maths lets you write 2(x + 1). Python reads it as calling the number 2.

Breaks

y = 2(x + 1)

Works

y = 2 * (x + 1)

3. A function and a variable with the same name

Storing a result under the function's own name replaces the function.

Breaks

def score(a, b):
    return a + b

score = score(2, 3)
print(score(4, 5))

Works

def score(a, b):
    return a + b

result = score(2, 3)
print(score(4, 5))

How to find it in your own code

Checklist: 1) Find the name just before the ( on the failing line. 2) Add print(type(name)) above it; if it prints <class 'int'>, search upward for where that name was given a number. 3) Rename the variable. Never use sum, max, min, len, round, int, str, list or input as variable names. 4) In formulas, write every * explicitly.

Try it: fix this bug

easy

class_report([40, 60, 80]) crashes: TypeError: 'int' object is not callable.

def class_report(scores):
    sum = 0
    for s in scores:
        sum += s
    passed = sum(1 for s in scores if s >= 50)
    return [sum, passed]
Open with hintsRuns in your browser. 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.

Related error guides

View all type errors →