Facebook Page Twitter Page LinkedIn Page
× Python Tutorial Python Advanced Python Resources Python Libraries


The Python while keyword is used to create a while loop. The While loop allows a set of statements to be executed repeatedly until a given condition is true.

Syntax

while condition:
      statements

Flow Diagram:

Python While Loop

In below mentioned example, program uses while loop to sum all integers from 1 to 5.

sum = 0
i = 1
while (i < 6):
    sum = sum + i
    i = i+1
print(sum)

The output of the above code will be:

15

❮ Python Keywords