Answer the question
In order to leave comments, you need to log in
Adding list elements via sum in python doesn't work, why?
Good afternoon!
Code:
list = [1, 2, 3, 4]
sum(list)
Throws an error:
TypeError Traceback (most recent call last)
in ()
12
13 list = [1, 2, 3, 4]
---> 14 sum (list)
TypeError: 'int' object is not callable
What could be the problem, like sum is applied to lists or not?
Answer the question
In order to leave comments, you need to log in
Somewhere above you overridden the value of the "sum" built-in function to a number ( sum=0
).
Do not use the names of built-in functions for your own variables (sum, list).
most likely somewhere earlier in the code the sum variable, which contains int, is redefined, the code is working
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question