How Will You Print The Sum Of Numbers Starting From 1 To 100 (Inclusive Of Both)?


print sum(range(1,101))
#range() returns a list to the sum function containing
#all the numbers from 1 to 100. Please see that
#the range function does not include the end given (101 here).
print(sum(xrange(1, 101)))
#xrange() returns an iterator rather than a list
#which is less heavy in the memory.



© 2017