0

What is sum in python

Plss help

30th Nov 2019, 6:23 PM
DELETED ACCOUNT
9 Respostas
+ 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! :)
30th Nov 2019, 6:38 PM
Gonçalo Magalhaes
Gonçalo Magalhaes - avatar
+ 2
cool............
30th Nov 2019, 7:56 PM
DELETED ACCOUNT
+ 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!
30th Nov 2019, 6:32 PM
Gonçalo Magalhaes
Gonçalo Magalhaes - avatar
+ 1
this is + ?
30th Nov 2019, 6:34 PM
DELETED ACCOUNT
+ 1
tnx!!!!!
30th Nov 2019, 6:38 PM
DELETED ACCOUNT
+ 1
You can "convert" individual elements into an iterable by using double brackets. e.g print(sum((1, 2, 3, 4, 5)))
30th Nov 2019, 7:51 PM
rodwynnejones
rodwynnejones - avatar
+ 1
rodwynnejones Your coding is correct. You're actually creating a tuple object with those numbers and feeding it to sum()
30th Nov 2019, 7:55 PM
Gonçalo Magalhaes
Gonçalo Magalhaes - avatar
0
who like coding???????????
30th Nov 2019, 7:57 PM
DELETED ACCOUNT
0
Everyone who is interestedddddd
1st Dec 2019, 5:30 PM
onekpsc