Python Tutorial Python Advanced Python Resources Python Libraries
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

Python while Keyword

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.


while condition:

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

The output of the above code will be:


❮ Python Keywords