+ 3

mySum = sum (range (5)) ?

mySum contain 10 how, explain working principle?

27th Dec 2016, 1:39 PM
Ankit Kumar
Ankit Kumar - avatar
3 Answers
+ 8
range(5) creates a range object, that contains all integers from 0 to 4, if you convert it to a list you'll get [0, 1, 2, 3, 4]. sum() function summarizes all elements of iterable, so in your case it'll be 0+1+2+3+4=10
27th Dec 2016, 1:47 PM
Dmitry Zolnikov
Dmitry Zolnikov - avatar
+ 2
"range(5)" generates the integers 0, 1, 2, 3, 4 "sum" sums them up, thus 0+1+2+3+4 = 10
15th Jan 2017, 4:22 PM
Diego
Diego - avatar
- 1
Podem me arranjar um scratch de jeito!
1st Jan 2017, 7:35 PM
AntĂłnio Morais
AntĂłnio Morais - avatar