sds2019
sds2019 copied to clipboard
sum([1,2,3]) error: TypeError: 'int' object is not callable
Hi,
I have been playing around with Python in Jupyter Notebook (not necessarily directly relevant for the assignment). I tried to run the sum() function on a list with a start value of 10:
thirdlist=[1,2,3,4,5] x = sum(thirdlist,10) print(x)
I get the following output:
`---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
TypeError: 'int' object is not callable`
I can't seem to understand what I'm doing wrong? I've tried Googling without any look. Moreover, when I try the same code in SublimeText and PythonTutor's Visualizer, it seems to give the correct output (25).
Thank you, Andreas
Hi Andreas,
What does the rest of your notebook look like? Did you "overwrite" the sum()
function by assigning an integer value to sum
somewhere in the script? That might explain why it works fine when run on its own elsewhere.
As Mathias pointed out, you have most likely overwritten the variable sum
somewhere earlier in your code. I.e. your code contains something like
sum = 2+3
sum([1,2,3]) # Fails
What you are doing is then something like 5([1,2,3])
and since 5
is not callable you get an error.
Hey Kristian and Mathias, thanks! I did 'define' it in several places. I have renamed them so they're all unique and it works smoothly now :)
Thanks!
Great! I'm reopening the issue to make it easier for others to find.