0% found this document useful (0 votes)
10 views3 pages

Mastering For Loops in Python

Uploaded by

hydrogenproton1
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)
10 views3 pages

Mastering For Loops in Python

Uploaded by

hydrogenproton1
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
You are on page 1/ 3

Mastering For Loops in

Python
This presentation will guide you through the use of for loops in
Python. For loops are essential for traversing sequences. We'll
explore syntax and examples. Grasp how to iterate lists, strings,
tuples, and dictionaries effectively.

by Aditya Pandey
For Loop Syntax and Traversal
Basic Syntax Example Output

for iterator_var in sequence:


n = 4 0
defines a loop that executes
for i in range(0, n): 1
statements for each element
print(i) 2
3

The for in loop is a powerful iteration mechanism in Python, allowing you to systematically process each element in
a sequence. This example demonstrates iterating through a range of numbers, printing each index from 0 to 3.
Iterating Through Data Structures
Lists

li = ["geeks", "for", "geeks"]


for i in li:
print(i)

Tuples

tup = ("geeks", "for", "geeks")


for i in tup:
print(i)

Strings

s = "Geeks"
for i in s:
print(i)

Dictionaries

d = dict({'x':123, 'y':354})
for i in d:
print("%s %d" % (i, d[i]))

For loops can traverse various data structures. The code snippets demonstrate iteration. Iteration is possible through lists,
tuples, strings, and dictionaries.

You might also like