for loop in Python

for loop is the most common iterating logic that we used in every programming or scripting. But today, here we will see, how we can write that same for loop in python.

Generally, for loop is used to iterate through any iterables. For e.g. we have a list few fruits in a basket and we want list down what are those fruits. So, we will iterate each fruit from that basket and will find out each of them.

But before that, let's check the basic syntax of for loop.

for <iterated element> in <iterable>:

So, at above, for is the key word and iterated element is the variable which will hold individual element on each loop. Whereas, iterable is the elements that we want to loop through.

Now, let's go through our fruit basket example and write a for loop to iterate each fruits from that basket.

basket = ["Mango", "Apple", "Guava", "Orange"]
for fruit in basket:
    print (fruit)

Output of above code:

Mango
Apple
Guava
Orange

THAT'S IT