SlideShare a Scribd company logo
3
Most read
10
Most read
16
Most read
Python programming-for
loops
Quick revision
 What is a list?
 Difference between list and a variable
 Can list store data of multiple types?
 What is used to iterate over a list?
 How to calculate length of list?
 Are strings stored as lists in python?
What is for loop???
 The for loop in Python is used to iterate over
a sequence (list, tuple, string) or other
iterable objects.
 Iterating over a sequence is called traversal.
2 types of writing for loops
1.Getting each element of the sequence
2.Range (): By generating range of numbers and
use these numbers as indexes to access
sequences.
Lets dive in type 1 of for loop
Syntax of for loop
Example
Flowchart of for loop
Iterating over string
Example 2:For loop to calculate sum
of elements in a list
The break statement
 Exit the loop when x is "banana", but this time the
break comes before the print:
Continue keyword
 With the continue statement we can stop the
current iteration of the loop, and continue with
the next:
Type 2 of for loop
The range() function
 We can generate a sequence of numbers using
range() function. range(10) will generate
numbers from 0 to 9 (10 numbers).
 We can also define the start, stop and step size
as range(start,stop,step size). step size defaults
to 1 if not provided.
 To force this function to output all the items, we
can use the function list().
Example
Example to use range() in for loop
 Syntax : range(start index, end index, step size)
Sample problems
 Print elements of a 1 dimensional list.
 Print elements of 2 dimensional list.
 Print even elements in a list.
This work is licensed under a Creative Commons
Attribution-ShareAlike 3.0 Unported License.
It makes use of the works of Mateus Machado Luna.

More Related Content

What's hot (20)

PPTX
Introduction to the basics of Python programming (part 1)
Pedro Rodrigues
 
PPT
Introduction to Python
Nowell Strite
 
PDF
Introduction To Python | Edureka
Edureka!
 
PDF
Strings in python
Prabhakaran V M
 
PDF
Python Programming Language | Python Classes | Python Tutorial | Python Train...
Edureka!
 
PDF
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Edureka!
 
PPTX
Beginning Python Programming
St. Petersburg College
 
PPTX
MatplotLib.pptx
Paras Intotech
 
PPTX
Python programming
Ashwin Kumar Ramasamy
 
PPTX
Python strings presentation
VedaGayathri1
 
PDF
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Edureka!
 
PPTX
Looping Statements and Control Statements in Python
PriyankaC44
 
PPTX
Functions in Python
Kamal Acharya
 
PDF
Begin with Python
Narong Intiruk
 
PPSX
python Function
Ronak Rathi
 
PDF
Python basic
Saifuddin Kaijar
 
PDF
Introduction To Python
Vanessa Rene
 
PDF
Python recursion
Prof. Dr. K. Adisesha
 
PDF
Python Basics | Python Tutorial | Edureka
Edureka!
 
Introduction to the basics of Python programming (part 1)
Pedro Rodrigues
 
Introduction to Python
Nowell Strite
 
Introduction To Python | Edureka
Edureka!
 
Strings in python
Prabhakaran V M
 
Python Programming Language | Python Classes | Python Tutorial | Python Train...
Edureka!
 
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Edureka!
 
Beginning Python Programming
St. Petersburg College
 
MatplotLib.pptx
Paras Intotech
 
Python programming
Ashwin Kumar Ramasamy
 
Python strings presentation
VedaGayathri1
 
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Edureka!
 
Looping Statements and Control Statements in Python
PriyankaC44
 
Functions in Python
Kamal Acharya
 
Begin with Python
Narong Intiruk
 
python Function
Ronak Rathi
 
Python basic
Saifuddin Kaijar
 
Introduction To Python
Vanessa Rene
 
Python recursion
Prof. Dr. K. Adisesha
 
Python Basics | Python Tutorial | Edureka
Edureka!
 

Similar to Python for loop (20)

PDF
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
Michpice
 
PPTX
python_computer engineering_semester_computer_language.pptx
MadhusmitaSahu40
 
PPTX
Practical Python.pptx Practical Python.pptx
trwdcn
 
PPTX
Q-SPractical_introduction_to_Python.pptx
JeromeTacata3
 
PPTX
Q-Step_WS_02102019_Practical_introduction_to_Python.pptx
nyomans1
 
PPT
ppt3-conditionalstatementloopsdictionaryfunctions-240731050730-455ba0fa.ppt
avishekpradhan24
 
PPTX
Python Development Workshop DAY 06 QUEST
AttaMohammadPanhyar
 
PPT
PPT3-CONDITIONAL STATEMENT LOOPS DICTIONARY FUNCTIONS.ppt
RahulKumar812056
 
PPTX
Introduction to python programming ( part-3 )
Ziyauddin Shaik
 
PPTX
Python programming
sirikeshava
 
PPTX
Mastering Python lesson3b_for_loops
Ruth Marvin
 
PPT
PE1 Module 3.ppt
balewayalew
 
PDF
While-For-loop in python used in college
ssuser7a7cd61
 
PPTX
While_for_loop presententationin first year students
SIHIGOPAL
 
PDF
Introduction-to-Iteration.pdf
KeshavBandil2
 
PPTX
Learn more about the concepts of Data Types in Python
PrathamKandari
 
PDF
loops python.pdf
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
PPTX
Python for Beginners(v3)
Panimalar Engineering College
 
PDF
Python Programming Module 3 (2).pdf
Thanmayee S
 
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
Michpice
 
python_computer engineering_semester_computer_language.pptx
MadhusmitaSahu40
 
Practical Python.pptx Practical Python.pptx
trwdcn
 
Q-SPractical_introduction_to_Python.pptx
JeromeTacata3
 
Q-Step_WS_02102019_Practical_introduction_to_Python.pptx
nyomans1
 
ppt3-conditionalstatementloopsdictionaryfunctions-240731050730-455ba0fa.ppt
avishekpradhan24
 
Python Development Workshop DAY 06 QUEST
AttaMohammadPanhyar
 
PPT3-CONDITIONAL STATEMENT LOOPS DICTIONARY FUNCTIONS.ppt
RahulKumar812056
 
Introduction to python programming ( part-3 )
Ziyauddin Shaik
 
Python programming
sirikeshava
 
Mastering Python lesson3b_for_loops
Ruth Marvin
 
PE1 Module 3.ppt
balewayalew
 
While-For-loop in python used in college
ssuser7a7cd61
 
While_for_loop presententationin first year students
SIHIGOPAL
 
Introduction-to-Iteration.pdf
KeshavBandil2
 
Learn more about the concepts of Data Types in Python
PrathamKandari
 
Python for Beginners(v3)
Panimalar Engineering College
 
Python Programming Module 3 (2).pdf
Thanmayee S
 
Ad

Recently uploaded (20)

PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
Difference between write and update in odoo 18
Celine George
 
PDF
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PDF
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
PPTX
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PPTX
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
PPTX
infertility, types,causes, impact, and management
Ritu480198
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PDF
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
PDF
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PPTX
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
PPTX
Controller Request and Response in Odoo18
Celine George
 
PDF
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
DAY 1_QUARTER1 ENGLISH 5 WEEK- PRESENTATION.pptx
BanyMacalintal
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
Difference between write and update in odoo 18
Celine George
 
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
infertility, types,causes, impact, and management
Ritu480198
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
Controller Request and Response in Odoo18
Celine George
 
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
DAY 1_QUARTER1 ENGLISH 5 WEEK- PRESENTATION.pptx
BanyMacalintal
 
Ad

Python for loop

  • 2. Quick revision  What is a list?  Difference between list and a variable  Can list store data of multiple types?  What is used to iterate over a list?  How to calculate length of list?  Are strings stored as lists in python?
  • 3. What is for loop???  The for loop in Python is used to iterate over a sequence (list, tuple, string) or other iterable objects.  Iterating over a sequence is called traversal.
  • 4. 2 types of writing for loops 1.Getting each element of the sequence 2.Range (): By generating range of numbers and use these numbers as indexes to access sequences.
  • 5. Lets dive in type 1 of for loop
  • 10. Example 2:For loop to calculate sum of elements in a list
  • 11. The break statement  Exit the loop when x is "banana", but this time the break comes before the print:
  • 12. Continue keyword  With the continue statement we can stop the current iteration of the loop, and continue with the next:
  • 13. Type 2 of for loop
  • 14. The range() function  We can generate a sequence of numbers using range() function. range(10) will generate numbers from 0 to 9 (10 numbers).  We can also define the start, stop and step size as range(start,stop,step size). step size defaults to 1 if not provided.  To force this function to output all the items, we can use the function list().
  • 16. Example to use range() in for loop
  • 17.  Syntax : range(start index, end index, step size)
  • 18. Sample problems  Print elements of a 1 dimensional list.  Print elements of 2 dimensional list.  Print even elements in a list.
  • 19. This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. It makes use of the works of Mateus Machado Luna.