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

PPTX
Python Flow Control
Kamal Acharya
 
PDF
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Edureka!
 
PPTX
List in Python
Sharath Ankrajegowda
 
PDF
Python Variable Types, List, Tuple, Dictionary
Soba Arjun
 
PPTX
Loops in Python.pptx
Guru Nanak Dev University, Amritsar
 
PPT
Python Control structures
Siddique Ibrahim
 
PDF
File handling in Python
BMS Institute of Technology and Management
 
PDF
Python If Else | If Else Statement In Python | Edureka
Edureka!
 
Python Flow Control
Kamal Acharya
 
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Edureka!
 
List in Python
Sharath Ankrajegowda
 
Python Variable Types, List, Tuple, Dictionary
Soba Arjun
 
Python Control structures
Siddique Ibrahim
 
Python If Else | If Else Statement In Python | Edureka
Edureka!
 

What's hot (20)

PPTX
Data types in python
RaginiJain21
 
PPTX
Python 3 Programming Language
Tahani Al-Manie
 
PPTX
Python Data-Types
Akhil Kaushik
 
PDF
Datatypes in python
eShikshak
 
PPTX
Python Functions
Mohammed Sikander
 
PPTX
Python Basics
Pooja B S
 
PPTX
Looping Statements and Control Statements in Python
PriyankaC44
 
PPTX
Introduction to the basics of Python programming (part 1)
Pedro Rodrigues
 
PDF
Python-03| Data types
Mohd Sajjad
 
PPTX
Conditional and control statement
narmadhakin
 
PPTX
Python basics
RANAALIMAJEEDRAJPUT
 
PPT
Python Pandas
Sunil OS
 
PDF
Introduction To Python
Vanessa Rene
 
PPTX
Beginning Python Programming
St. Petersburg College
 
PPSX
Modules and packages in python
TMARAGATHAM
 
PPT
Introduction to Python
amiable_indian
 
PDF
Zero to Hero - Introduction to Python3
Chariza Pladin
 
PPTX
Functions in Python
Kamal Acharya
 
PPTX
Data Structures in Python
Devashish Kumar
 
Data types in python
RaginiJain21
 
Python 3 Programming Language
Tahani Al-Manie
 
Python Data-Types
Akhil Kaushik
 
Datatypes in python
eShikshak
 
Python Functions
Mohammed Sikander
 
Python Basics
Pooja B S
 
Looping Statements and Control Statements in Python
PriyankaC44
 
Introduction to the basics of Python programming (part 1)
Pedro Rodrigues
 
Python-03| Data types
Mohd Sajjad
 
Conditional and control statement
narmadhakin
 
Python basics
RANAALIMAJEEDRAJPUT
 
Python Pandas
Sunil OS
 
Introduction To Python
Vanessa Rene
 
Beginning Python Programming
St. Petersburg College
 
Modules and packages in python
TMARAGATHAM
 
Introduction to Python
amiable_indian
 
Zero to Hero - Introduction to Python3
Chariza Pladin
 
Functions in Python
Kamal Acharya
 
Data Structures in Python
Devashish Kumar
 
Ad

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
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
 
PPTX
Loops in python including control statements and various test cases
AnuragSharma710741
 
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
Michpice
 
python_computer engineering_semester_computer_language.pptx
MadhusmitaSahu40
 
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
 
Loops in python including control statements and various test cases
AnuragSharma710741
 
Ad

Recently uploaded (20)

PDF
High Ground Student Revision Booklet Preview
jpinnuck
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PDF
Module 3: Health Systems Tutorial Slides S2 2025
Jonathan Hallett
 
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
Sourav Kr Podder
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PPTX
How to Manage Global Discount in Odoo 18 POS
Celine George
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
PPTX
Strengthening open access through collaboration: building connections with OP...
Jisc
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PPTX
IMMUNIZATION PROGRAMME pptx
AneetaSharma15
 
PDF
Arihant Class 10 All in One Maths full pdf
sajal kumar
 
PDF
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
Sourav Kr Podder
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
PPTX
Congenital Hypothyroidism pptx
AneetaSharma15
 
PPTX
Introduction and Scope of Bichemistry.pptx
shantiyogi
 
DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
BANDITA PATRA
 
PPTX
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
High Ground Student Revision Booklet Preview
jpinnuck
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Module 3: Health Systems Tutorial Slides S2 2025
Jonathan Hallett
 
Open Quiz Monsoon Mind Game Final Set.pptx
Sourav Kr Podder
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
How to Manage Global Discount in Odoo 18 POS
Celine George
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
Strengthening open access through collaboration: building connections with OP...
Jisc
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
IMMUNIZATION PROGRAMME pptx
AneetaSharma15
 
Arihant Class 10 All in One Maths full pdf
sajal kumar
 
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
Open Quiz Monsoon Mind Game Prelims.pptx
Sourav Kr Podder
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
Congenital Hypothyroidism pptx
AneetaSharma15
 
Introduction and Scope of Bichemistry.pptx
shantiyogi
 
UPPER GASTRO INTESTINAL DISORDER.docx
BANDITA PATRA
 
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 

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.