Home
Aptitude
Categories


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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.