Q:

Python | Demonstrate an example of for each loop

0

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<a.< p="" style="box-sizing: border-box;"></a.<>

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now