python for loop – top 10 examples to get started now

A for loop in Python is used to repeat a block of code for a certain number of times or until a certain condition is met. for loop  is used to iterate over a sequence of elements such as a list, tuple, string, ,range or dictionary.

The general syntax of a for loop in Python is:

for variable in sequence:
 # code to be executed
The sequence can be any iterable object like a list, tuple, string, etc.

The variable takes on the values in the sequence one by one with each iteration and execute the code to process the variable, as in simplest case just print the variable value in each pass.

Here are top 10 python for loop examples which are very helpful to python beginners to get started with python basics.

 

Comments

This site uses Akismet to reduce spam. Learn how your comment data is processed.