# How to Find the Sum of Natural Numbers using Python?

PythonServer Side ProgrammingProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

You can use while loop to successively increment value of a variable i by one and adding it cumulatively.

s,i=0,0
n=10
while i<n:
i=i+1
s=s+i
print ("sum of first 10 natural numbers",s)

For loop is also used to loop over a range of natural numbers and add them cumulatively.

s=0
for i in range(11):
s=s+i
print ("sum of first 10 natural numbers",s)

Lastly using the built in function sum() also gives sum of a range of numbers

s=sum(range(11))
print ("sum of first 10 natural numbers",s)

Updated on 21-Feb-2020 12:54:53