[Easy Python] int object is not callable
This error happens if we try to use int value as a function. For example, if you create an int variable that has the same name as some function and after tries to call this function, or maybe you missed some operator in the arithmetic notation: wrong - 2(5+4), correct - 2*(5+4).
numbers = [1, 2, 3, 4]
sum = 0
sum = sum(numbers)
print("The total sum of the list numbers is: " + str(sum) + ".")
Output:
Traceback (most recent call last):
File "main.py", line 5, in <module>
sum = sum(numbers)
TypeError: 'int' object is not callable
For the resolve current example enough to rename variable sum -> total_sum:
numbers = [1, 2, 3, 4]
total_sum = 0
total_sum = sum(numbers)
print("The total sum of the list numbers is: " + str(total_sum) + ".")
Output:
The total sum of the list numbers is: 10.
p.s. Be attaching when declaring variables and writing complex arithmetic formulas.