Home >Backend Development >Python Tutorial >How to Fix Python\'s \'TypeError: \'int\' object is not callable\' Error?
Eliminating 'TypeError: 'int' object is not callable' Error in Python
When encountering the error "TypeError: 'int' object is not callable" in Python, it typically indicates a naming conflict with the built-in function round(). Here's an exploration of the issue and its resolution.
Consider the following Python code:
a = 23 b = 45 c = 16 round((a/b)*0.9*c)
Running the code above results in an error message like:
TypeError: 'int' object is not callable.
To understand this error, we need to examine the code more closely. We are attempting to use the round() function to round the result of the expression ((a/b)0.9c). However, somewhere else in the code, an assignment like the following may be present:
round = 42
This assignment reassigns the name round to the integer 42. When we later write round((a/b)0.9c), the Python interpreter interprets it as an attempt to invoke a function named round on the integer 42, which is not possible. As a result, the "TypeError: 'int' object is not callable" error is raised.
Solution:
To resolve this issue, the code that binds round to an integer should be removed. This can be achieved by searching through the codebase for instances where the name round is assigned a value other than the round() function and removing such assignments.
Once the name conflict is resolved, the code should execute without the error. The expression ((a/b)0.9c) will be rounded to the nearest integer and the result will be displayed.
The above is the detailed content of How to Fix Python's 'TypeError: 'int' object is not callable' Error?. For more information, please follow other related articles on the PHP Chinese website!