Python For Loop

In python there are two type of loop.

  • For loop
  • While loop

In this post we are going to explain for loop.
for loops are used when you have a block of code which you want to repeat a fixed number of times. The for-loop is always used in combination with an iterable object, like a list or a range. The Python for statement iterates over the members of a sequence in order, executing the block each time.
Note:Python for loop can be used when there are no size given of list and dict.

For example:
                      
        for i in range(10):
            print(i)
                      
Output: 0
        1
        2
        3
        4
        5
        6
        7
        8
        9

                    

We can also use to for loop to get items from lists.

                      
        li = ['Orange','Apple','Banana']
        for i in li:
            print(i)
                      
Output: Orange
        Apple
        Banana