Estimated reading time: 1 minute
We have posted several python solutions to TypeErrors here on the website. Here is another one we hope you will find useful in solving a programming issue you may have.
So what does the error mean?
In the below code, we have four variables that have been assigned an integer.
a= 10
b= 11
c= 12
int= 13
d = int(a/b*c)
print(d)
As can be seen we also have a variable d that is assigned to a function int , that is using the variables a,b,c.
As int is a function it cannot be assigned as a variable, and for this reason the below error will appear:
d = int(a/b*c)
TypeError: 'int' object is not callable
So how can this be fixed?
The solution to this is quite straight forward, it is important not to assign a function as a variable. The fix you would apply is as follows:
Incorrect code:
a= 10
b= 11
c= 12
int = 13 ===> change this line to fix the error
d = float(a/b*c)
print(d)
Corrected code:
a= 10
b= 11
c= 12
int_value = 13 ===> corrected line of code
d = float(a/b*c)
print(d)
Giving you the result:
10
As can also be seen with TypeError: ‘str’ object is not callable assign variables to functions should be avoided at all cost.