How to Fix: TypeError: ‘int’ object is not callable

3D illustration of a robot trying to use a number block as a telephone, representing the 'int object is not callable' error.

This error is very similar to 'str' object is not callable. One common error in Python is the TypeError int not callable, which means: “You are trying to use a number as if it were a function.”

A “callable” is anything you can put parentheses () after, like print() or my_function(). An integer, like 10, is just data.

Cause 1: Using Parentheses Instead of Brackets

This is a simple syntax mistake. You meant to get an item from a list (using []), but you used parentheses () by accident.

Problem Code:

my_list = [10, 20, 30]
print(my_list(0)) # CRASH!
# You're trying to CALL the list.

The Fix: Use square brackets [] for indexing.

print(my_list[0]) # Correct! Output: 10

Cause 2: Overwriting a Function Name

This is the most common cause. You accidentally used a function name as a variable.

Problem Code:

# 'sum' is a built-in function that adds a list
my_list = [1, 2, 3]

# 1. You calculate the sum and store it in a variable...
# ... but you accidentally named it 'sum'!
sum = sum(my_list) # sum is now the number 6

# 2. You try to use the 'sum' function again
other_list = [4, 5, 6]
new_sum = sum(other_list)
# CRASH! TypeError: 'int' object (the number 6) is not callable

The Fix: NEVER use built-in function names as variable names.

my_list = [1, 2, 3]
total = sum(my_list) # Use a good variable name like 'total'

other_list = [4, 5, 6]
new_total = sum(other_list) # The 'sum' function is safe and sound.
print(new_total)

Similar Posts

Leave a Reply