Home »
Python »
Python programs
Python | Demonstrate an example of for each loop
Python for each loop example: Here, we are going to implement a program that will demonstrate examples/use of for each loop.
Submitted by Pankaj Singh, on October 08, 2018
Example:
for each loop is used with container type of data type like list, in this example, we have a list of fruits, we are printing its type and individual values (elements) using for each loop
Program:
# declare and initialize a list
fruits = ["apple","mango","guava","grapes","pinapple"]
# pritning type of fruits
print (type(fruits))
# printing value
for fruit in fruits:
print(fruit)
Output
<class 'list'>
apple
mango
guava
grapes
pinapple
Python Basic Programs »
ADVERTISEMENT
ADVERTISEMENT