Skip to content
Home » TypeError: ‘int’ object is not callable in Python

TypeError: ‘int’ object is not callable in Python

To solve TypeError: ‘int’ object is not callable in Python error follow below methods. Curly brackets have a special significance in Python. They are used to denote the invocation of a function. Python interprets a pair of curly brackets after a number without an operator between them as an attempt to call a function. This will result in the error “TypeError: ‘int’ object is not callable.”

ERROR LOG

TypeError: 'int' object is not callable

How to solve TypeError: ‘int’ object is not callable ?

When you try to call an integer, you get the “TypeError: ‘int’ object is not callable” error.

This can occur if a mathematical operator is left out of a calculation. This error can also occur if you mistakenly override a built-in function, such as round() or sum(), that you utilize later in your code ().

Refer the given methods to solve the issue.

Method 1: Missing any Mathematical or Arithmetic Operator

If you forget to use an arithmetic operator in your code while conducting mathematical calculations, you will get a TypeError: the ‘int’ object is not a callable error.

Example

a = 5
b = a(a + 1)
print(b)

Output:

Traceback (most recent call last):
  File "main.py", line 2, in <module>
	b = a(a + 1)
TypeError: 'int' object is not callable

The above error raised because I have missed a Arithmetic operator in the b = a(a + 1) statement. To correct it follow the below code.

a = 5
b = a*(a + 1)
print(b)

Output:

30

Method 2 : While using Reserved keywords as a function

When new to Python, the most typical mistakes made by developers include using reserved keywords as variables and calling them as functions. Let’s use a basic example to demonstrate this problem.

sum = 0
sum = sum([1,2,3,4])
print("The sum of numbers is:", sum)

Output:

Traceback (most recent call last):
  File "main.py", line 2, in <module>
    sum = sum([1,2,3,4])
TypeError: 'int' object is not callable

In the preceding code, we declared the sum as a variable. In Python, on the other hand, sum() is a reserved term and a built-in method that sums the items of an iterable and returns the sum.

Outcome:

When you try to call the reserved keywords as a function or miss an arithmetic operator while conducting mathematical calculations, the TypeError: the ‘int’ object is not a callable issue is raised.

To avoid the problem while coding, developers should keep the following points in mind.

  • As Python variable names, never utilize built-in functions, modules, or reserved keywords.
  • While completing computations, make sure that no arithmetic operators are overlooked.
  • Do not override built-in functions like sum() and round() and then use the identical methods to perform operations later in your code.

Hope the above solution works.

Also read :

UnboundLocalError: local variable referenced before assignment Python
ImportError: No module named PIL