Typeerror: ‘int’ object is not callable: How to fix it in Python

In Python, curly brackets have a specific purpose. They serve as a symbol for a function call. Python will assume you are attempting to call a function if you supply a pair of curly braces after a number without placing an operator in between them. The message “TypeError: ‘int’ object is not callable” will appear as a result. This guide discusses the significance of this inaccuracy and the causes of it. To assist you in identifying the cause of the mistake in your code, we walk over a few examples of this error.

TypeError: ‘int’ object is not callable

Curly brackets are used to invoke Python functions. Consider the following function call statement:

calculate_tip(5, 10)

This function takes two arguments. The parameters we specified are 5 and 10. Since curly brackets have this unique meaning, they cannot be used to refer to an integer.

typeerror: 'int' object is not callable

The two most prevalent scenarios in which developers attempt to call an integer are:

  • The integer value of a function that has been reassigned
  • A missing math operator in a computation

Let’s analyze each instance one by one to assist you address the mistake you’re facing.

Method 1: Function Has an Integer Value

Example
myNums = [56,13,21,54] sum = 0 sum = sum(myNums) print("sum of myNums list: ", sum)
Output and explanation
Traceback (most recent call last): 

    File "C:\Users\Admin\.spyder-py3\temp.py", line 3, in <module> sum sum(myNums) 


TypeError: 'int' object is not callable
  1. Four integers are list in the variable myNums.
  2. Initializing a variable Sum with a value of 0
  3. With the help of the sum() function, the sum of the myNums list is determined and placed in the sum variable.
  4. It prints the results.

What took place here? Step 2 involves setting a variable named sum to zero. Sum is a predefined function in Python. Next, step 3 attempt to utilize the sum function is unsuccessful. Since step 2, Python just keeps track of the total as a variable. Sum() is now completely useless because it was declared a variable.

Solution

We can use more evocative variable names that are not preset in place of sum as a variable declaration, such as mySum, mySum, and totalSum. Be careful to adhere to PEP 8’s naming convention.

myNums = [56,13,21,54]
totalSum = 0
totalSum= sum(myNums)
print("sum of myNums list: ", totalSum)
Exact output
sum of myNums list: 144

Method 2: Missing a Mathematical Operator

Arithmetic operators are not provided when calculating integers

Equations without arithmetic operators may throw a TypeError: object “int” is not callable. Observe the example below:

prices = [44,54,24,67]
tax = 10
totalPrice = sum(prices)
taxAmount = totalPrice(tax/100)
print("total taxable amounr: ", taxAmount)
Output and Explanation
File "C:\Users\Admin\.spyder-py3\temp.py", line 4, in <module>
   taxAmount = totalPrice(tax/100) 

TypeError: 'int' object is not callable
  1. A collection of integers kept in variableprices
  2. The tax rate is fix at 10%.
  3. The totalPrice variable computes and stores the total price.
  4. Determine the whole taxable amount.
  5. The outcome is printed.

We must multiply totalPrice by the tax % in order to determine the taxable amount. The * operator is absent while computing taxAmount in step 4. Hence, TypeError is raised: There Is No Callable “int” Object

Solution

All operators must be stated unambiguously.

prices = [44,54,24,67]
tax = 10
totalPrice = sum(prices)
taxAmount = totalPrice*(tax/100)
print("total taxable amounr: ", taxAmount)
total taxable amount: 18.900000000000002

Add parenthesis after an integer

Example
1 ( 2 )
Output and Explanation
File "C:\Users\Admin\.spyder-py3\temp.py", line 2, in <module>
  1(2) 

TypeError: 'int' object is not callable

Parentheses should never be placed after a number, according to syntax. It’s crucial to confirm the operators are proper, just like in the prior section.

Solution

After an integer, no brackets are allowed. Display the proper operators.

1 * 2

Conclusion

When you attempt to call an integer, the message “TypeError: ‘int’ object is not callable” is shown. If you neglect to add an operator in the computation, this may occur. Using the built-in function name as a variable identifier and, where required, defining arithmetic signs can help you avoid mistakes.

We collaborate with a team of professionals and talented developers at ONEXTDIGITAL to construct user-friendly eCommerce websites, CMS websites, and web applications. If you have any questions or would want to learn more about this experience, kindly call us and we will gladly help you.

Read also

Empty List Python: How To Make And Remove It