0% found this document useful (0 votes)
4 views6 pages

For Loops in Python Explained

A for loop in Python allows you to repeat a task for each item in a group, such as printing the names of fruits in a list. The structure of a for loop consists of 'for item in group:' followed by an indented block of code that executes for each item. An example provided shows how to loop through a list of fruits and print each one.

Uploaded by

dindimathai33
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

For Loops in Python Explained

A for loop in Python allows you to repeat a task for each item in a group, such as printing the names of fruits in a list. The structure of a for loop consists of 'for item in group:' followed by an indented block of code that executes for each item. An example provided shows how to loop through a list of fruits and print each one.

Uploaded by

dindimathai33
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Understanding For Loops in

Python
A simple explanation
What is a For Loop?
• A for loop lets you repeat a task for every item
in a group.
• Example: Saying the name of every fruit in a
basket.
Example: Looping through Fruits
• fruits = ["apple", "banana", "cherry"]
• for fruit in fruits:
• print(fruit)
What This Does
• - Looks at each fruit in the list:
• - Prints 'apple'
• - Prints 'banana'
• - Prints 'cherry'
For Loop Structure
• for item in group:
• do something with item

• - 'item': temporary name for each element


• - 'group': the list or sequence
• - Indented code runs for each item
Visual: Looping Through a Basket of Fruits

apple banana cherry

print('apple') print('banana') print('cherry')

You might also like