Typeerror: int object is not callable – How to Fix in Python

Kolade Chris

In Python, a “Typeerror” occurs when you use different data types in an operation.
For example, if you attempt to divide an integer (number) by a string, it leads to a typeerror because an integer data type is not the same as a string.
One of those type errors is the “int object is not callable” error.
The “int object is not callable” error occurs when you declare a variable and name it with a built-in function name such as int() , sum() , max() , and others.
The error also occurs when you don’t specify an arithmetic operator while performing a mathematical operation.
In this article, I will show you how the error occurs and what you can do to fix it.
How to Fix Typeerror: int object is not callable in Built-in Function Names
If you use a built-in function name as a variable and call it as a function, you’ll get the “int object is not callable” error.
For instance, the code below attempts to calculate the total ages of some kids with the built-in sum() function of Python. The code resulted in an error because the same sum has already been used as a variable name:
Another example below shows how I tried to get the oldest within those kids with the max() function, but I had declared a max variable already:

Both code examples led to this error in the terminal:
To fix the issue, you need to change the name of the variable you named as a built-in function so the code can run successfully:
If you get rid of the custom variables, your code will still run as expected:
How to Fix Typeerror: int object is not callable in Mathematical Calculations

In Mathematics, if you do something like 4(2+3), you’ll get the right answer which is 20. But in Python, this would lead to the Typeerror: int object is not callable error.
To fix this error, you need to let Python know you want to multiply the number outside the parentheses with the sum of the numbers inside the parentheses.
To do this, you do this by specifying a multiplication sign (*) before the opening parenthesis:
Python allows you to specify any arithmetic sign before the opening parenthesis.
So, you can perform other calculations there too:
Final Thoughts
The Typeerror: int object is not callable is a beginner error in Python you can avoid in a straightforward way.
As shown in this article, you can avoid the error by not using a built-in function name as a variable identifier and specifying arithmetic signs where necessary.
Python TypeError: ‘int’ object is not callable
This is a common coding error that occurs when you declare a variable with the same name as inbuilt int() function used in the code. Python compiler gets confused between variable ‘int’ and function int() because of their similar names and therefore throws typeerror: ‘int’ object is not callable error.
To overcome this problem, you must use unique names for custom functions and variables.
Example
In the example above we have declared a variable named `int` and later in the program, we have also used the Python inbuilt function int() to convert the user input into int values.
Python compiler takes “int” as a variable, not as a function due to which error “TypeError: ‘int’ object is not callable” occurs.
How to resolve typeerror: ‘int’ object is not callable
To resolve this error, you need to change the name of the variable whose name is similar to the in-built function int() used in the code.
In the above example, we have just changed the name of variable “int” to “productType”.
How to avoid this error?
To avoid this error always keep the following points in your mind while coding:
'int' object is not callable
I thought it was because I had numerator(self) and numerator(self, n) but now I know Python doesn’t have method overloading ( function overloading ) so I renamed to get_numerator but that’s not the problems.
What could it be?
3 Answers 3
You’re using numerator as both a method name ( def numerator(. ) ) and member variable name ( self.numerator = n ). Use set_numerator and set_denominator for the method names and it will work.
By the way, Python 2.6 has a built-in fraction class.
You can’t overload the name numerator to refer to both the member variable and the method. When you set self.numerator = n , you’re overwriting the reference to the method, and so when you call f.numerator(2) , it’s trying to do a method call on the member variable, which is an int , and Python doesn’t let you do that. It’s like saying x = 2; x(4) — it just doesn’t make any sense.
You should rename the setter methods to set_numerator and set_denominator to remove this naming conflict.
You are using numerator as both a method name and a name for an instance attribute. Since methods are stored on the class, when you lookup that attribute you get the number, not the method. (Python will look up attributes on the instance before looking at the class.)
That is to say that on the line where you say f.numerator(2) , it looks up f.numerator and finds that it is 0 , then tries to call that 0 , which obviously shouldn’t work.
If you have any practical purpose for this code, you can use the stdlib fractions module: http://docs.python.org/library/fractions.html
- This is new in Python 2.6. If I needed to represent fractions but was using an earlier version of Python, I’d probably use sympy’s Rational type.
A more practical default value for denominator is probably 1 . (That way Fraction(5) would be five, not some undefined operation tending towards infinity.)
Rather than a prints method, it would be more typical to define __str__ and just print your object.
Your methods are just getting and setting an attribute. In Python, we generally do not use getters and setters—we just let users set our attributes.
Python TypeError: ‘int’ object is not callable
The TypeError: the ‘int’ object is not a callable error occurs if an arithmetic operator is missed while performing the calculations or the reserved keywords are declared as variables and used as functions,
In this tutorial, we will learn what int object is is not callable error means and how to resolve this TypeError in your program with examples.
What is TypeError: the ‘int’ object is not callable?
There are two main scenarios where developers try to call an integer.
- When you try to call the reserved keywords as a function
- Missing an Arithmetic operator while performing the calculation
Scenario 1: When you try to call the reserved keywords as a function
Using the reserved keywords as variables and calling them as functions are developers’ most common mistakes when they are new to Python. Let’s take a simple example to reproduce this issue.
Output
If you look at the above code, we have declared the sum as a variable. However, in Python, the sum() is a reserved keyword and a built-in method that adds the items of an iterable and returns the sum.
Since we have declared sum as a variable and used it as a function to add all the items in the list, Python will throw TypeError.
Solution
We can fix this error by renaming the sum variable to total_price , as shown below.
Output
Scenario 2: Missing an Arithmetic operator while performing the calculation
While performing mathematical calculations, if you miss an arithmetic operator within your code, it leads to TypeError: the ‘int’ object is not a callable error.
Let us take a simple example to calculate the tax for the order. In order to get the tax value, we need to multiply total_value*(tax_percentage/100) .
Output
We have missed out on the multiplication operator while calculating the tax value in our code, leading to TypeError by the Python interpreter.
Solution
We can fix this issue by adding a multiplication (*) operator to our code, as shown below.
Output
Conclusion
The TypeError: the ‘int’ object is not a callable error raised when you try to call the reserved keywords as a function or miss an arithmetic operator while performing mathematical calculations.
- Use descriptive and unique variable names.
- Never use any built-in function, modules, reserved keywords as Python variable names.
- Ensure that arithmetic operators is not missed while performing calculations.
- Do not override built-in functions like sum() , round() , and use the same methods later in your code to perform operations.

report this ad