0
What is sum in python
Plss help
9 Answers
+ 3
Mikicrep sum() helps you if you have an iterable. Evidently, if you want to sum all values from 1 to 9, you will not do 1+2+3+4+5+...
Much better would be:
sum(i for i in range(10))
Hope that helps! :)
+ 2
cool............
+ 1
Simply speaking, sum() is a function which receives an iterable as an input. However, items must be numbers, because sum() adds all iterable items to value 0.
Example: sum([1, 2, 3])
That will output 6.
Happy coding!
+ 1
this is + ?
+ 1
tnx!!!!!
+ 1
You can "convert" individual elements into an iterable by using double brackets. e.g
print(sum((1, 2, 3, 4, 5)))
+ 1
rodwynnejones Your coding is correct. You're actually creating a tuple object with those numbers and feeding it to sum()
0
who like coding???????????
0
Everyone who is interestedddddd