In this article, we will explain to you on how to fix the typeerror: int object is not callable error.
Python developers may often encounter an error and one of these errors is int object is not callable.
Why this python typeerror: ‘int’ object is not callable occur?
This python typeerror: ‘int’ object is not callable usually occurs once you are declaring a variable and naming it with a built-in function name like int(), sum(), max(), and others.
In addition, the error message occurs when you try to call a function that is not callable.
Here is an example on how the error occurs:
x = 5
result = x(10)In this example, we have assigned the value 5 to the variable x.
In the next line, we are trying to call x as a function and passing the argument 10 to it.
However, since x is not a function, Python raises the “TypeError ‘int’ object is not callable” error message.
Traceback (most recent call last):
File “C:\Users\Dell\PycharmProjects\pythonProject\main.py”, line 2, in
result = x(10)
TypeError: ‘int’ object is not callable
Causes the Error Message?
The “TypeError ‘int’ object is not callable” error message is caused by two main reasons:
- Trying to call a variable as a function.
- Using parentheses after a variable that is not a function.
How to solve the Typeerror: int object is not callable in Built-in Function Names
When we are using a built-in function name as a variable and we call it as a function, we will get the “int object is not callable” error.
For example:
kid_ages = [1, 3, 5, 7, 9]
sum = 0
sum = sum(kid_ages)
print(sum)The list of numbers is defined on the first line of the program as “kid_ages”, with the values [1, 3, 5, 7, 9].
Next, a variable named “total_sum” is initialized to zero.
Then, the built-in Python function “sum()” is called with the argument “kid_ages” to calculate the sum of all the values in the list.
The result is then assigned to the variable “total_sum”.
Finally, the result stored in “total_sum” is printed to the console using the “print()” function.
The output will raise an error:
Traceback (most recent call last):
File “C:\Users\Dell\PycharmProjects\pythonProject\main.py”, line 4, in
sum = sum(kid_ages)
TypeError: ‘int’ object is not callable
To solve this error, you need to modify the name of the variable you named as a built-in function.
For that, the code will run successfully:
kid_ages = [1, 3, 5, 7, 9]
total_sum = 0
total_sum = sum(kid_ages)
print(total_sum)In this example code, the variable name “sum” has been changed to “total_sum” to avoid conflicts with the built-in function named “sum()”.
Solution to solve Typeerror: int object is not callable in Mathematical Calculations
In Math, when you do something like 10(5+8), you will get the right answer which is 130. Yet, if you do this in Python, you will get the Typeerror int object is not callable error.
C:\Users\Dell\PycharmProjects\pythonProject\main.py:1: SyntaxWarning: ‘int’ object is not callable; perhaps you missed a comma?
10(5+8)
Traceback (most recent call last):
File “C:\Users\Dell\PycharmProjects\pythonProject\main.py”, line 1, in
10(5+8)
TypeError: ‘int’ object is not callable
To solve this error, we should let Python know that we want to multiply the number outside the parentheses with the sum of the numbers inside the parentheses.
We can do this, through defining a multiplication sign (*) before the opening parenthesis:
For example:
print(10*(5+8))The code “print(10*(5+8))” is a simple Python expression that prints the result of a mathematical calculation to the console.
The expression first evaluates the value inside the parentheses, which is the sum of two numbers: 5 and 8. This results in a value of 13.
Then, the expression multiplies this value by 10, resulting in a final value of 130.
The “print()” function is used to output this value to the console, so the output of the code will be:
130
In Python, you are able to use any arithmetic operator before an opening parenthesis to perform calculations within it.
Therefore, we can also perform multiple operations:
For addition
print(10+(5+8))Output:
23
For subtraction:
print(10-(5+8))Output:
-3
For division:
print(10/(5+8))Output:
0.7692307692307693
Additional Resources
- Typeerror object of type decimal is not json serializable [SOLVED]
- typeerror: this.getoptions is not a function
- Typeerror: ‘float’ object cannot be interpreted as an integer
- Typeerror argument of type int is not iterable
- Typeerror can only concatenate str not nonetype to str
Frequently Asked Questions
What is Python TypeError and what causes it?
TypeError is raised when an operation is applied to an object of the wrong type. Common patterns: calling a non-callable object, adding incompatible types (str + int), passing the wrong number of arguments, or accessing attributes on a NoneType. Each TypeError message names the operation and expected vs actual types, the fix is almost always to convert types explicitly (int(), str()) or fix the wrong variable assignment.
How do I quickly debug a Python TypeError?
Three steps: (1) Read the full error message, it names the exact operation and types involved. (2) Print the type of every variable in that line: print(type(var1), type(var2)). (3) Check what the function expected vs what you passed. Most TypeError fixes are 1-line type casts or fixing a variable that became None unexpectedly.
Should I catch TypeError or let it propagate?
For internal code, let TypeError propagate, it’s almost always a real bug (wrong type passed). For boundary code (parsing user input, third-party API responses), catch TypeError + ValueError together: try: parsed = int(value) except (TypeError, ValueError): parsed = 0. Catching internal TypeErrors hides bugs.
How do I prevent TypeError in production?
Three patterns: (1) Use type hints (def add(a: int, b: int) -> int) and check with mypy / pyright in CI. (2) Validate inputs at boundaries (Pydantic for FastAPI, DRF serializers for Django). (3) Default values that match expected types (return 0 not None for numeric functions). Static typing catches 80% of TypeErrors before runtime.
Where can I find more TypeError fixes?
Browse the TypeError reference hub for 220+ specific TypeError fixes. For broader Python debugging, see the Python Tutorial hub. For related error types, see ValueError and AttributeError guides.
Conclusion
In conclusion, we’ve discussed on how to solve the error and also we provide some solutions to solve it.
Also, we’ve explained why this error occurs in provide some useful examples to follow.
FAQs
The error occurs when you did not define an arithmetic operator while performing a mathematical operation.
Yes, you can prevent this error message from occurring by ensuring that you are calling a function and not a variable, and by ensuring that you are using parentheses only after a function.
