Python Loops

In this tutorial you will learn about the Python Loops and its application with practical example.

Python Loops

In Python, loops statements are used to execute the block of code repeatedly for a specified number of times or until it meets a specified condition. In Python Programming Language we have following loops –

  • Python for loop
  • Python while loop
  • Python nested loop

Python for Loop

The for loop in Python takes a collection of data(list, tuple, string) and iterate the items one at a time in sequence.

Syntax:-

Example:-

Output:-

Python while Loop

The while loop will execute a block of statement as long as a test expression is true.

Syntax:-

Example:-

Output:-

Python Nested Loops

When there is loop statement inside another loop statement then it is termed as nested loop statement.

Syntax:- Nested for loop

Syntax:- Nested while loop

Note:- In nesting a loop we can put any type of loop inside of any other type of loop, it is possible to have for loop inside a while loop or vice versa.

In this tutorial we have learn about the Python Loops and its application with practical example. I hope you will like this tutorial.