SlideShare a Scribd company logo
3
Most read
6
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
Looping statement in python
PPTX
Loops in Python
PDF
التنمر الاكتروني
PPT
Python List.ppt
PDF
Strings in python
PPTX
Nested loops
PDF
Strings in Python
PDF
التنمر الالكتروني - خلود
Looping statement in python
Loops in Python
التنمر الاكتروني
Python List.ppt
Strings in python
Nested loops
Strings in Python
التنمر الالكتروني - خلود

What's hot (20)

PDF
Datatypes in python
PPT
Introduction to Python
PPTX
Variables in python
PDF
Python list
PDF
Python tuple
PPTX
Python basics
PPTX
Python Functions
PPTX
Introduction to python
PPTX
Python dictionary
PDF
Tuples in Python
PDF
What is Python Lambda Function? Python Tutorial | Edureka
PPT
Python ppt
PDF
Python Flow Control
PPTX
Chapter 14 strings
PDF
C++ OOPS Concept
PPTX
List in Python
PPTX
Fundamentals of Python Programming
PPTX
Looping Statements and Control Statements in Python
PDF
Introduction to Python
PDF
Control Structures in Python
Datatypes in python
Introduction to Python
Variables in python
Python list
Python tuple
Python basics
Python Functions
Introduction to python
Python dictionary
Tuples in Python
What is Python Lambda Function? Python Tutorial | Edureka
Python ppt
Python Flow Control
Chapter 14 strings
C++ OOPS Concept
List in Python
Fundamentals of Python Programming
Looping Statements and Control Statements in Python
Introduction to Python
Control Structures in Python
Ad

Similar to Python for loop (20)

PDF
advanced python for those who have beginner level experience with python
PDF
Advanced Python after beginner python for intermediate learners
DOCX
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
PPT
Python - Data Collection
DOCX
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
PPTX
Lecture 09.pptx
PPTX
Python Revision Tour.pptx class 12 python notes
PPTX
PRESENTATION ON STRING, LISTS AND TUPLES IN PYTHON.pptx
ODP
Python slide.1
PPTX
Chapter - 2.pptx
PDF
Python 3.x quick syntax guide
PPTX
Introduction to python programming ( part-3 )
PDF
Tuple Operation and Tuple Assignment in Python.pdf
PDF
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
DOCX
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
DOCX
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
PPTX
Basic of Python- Hands on Session
PDF
Python Interview Questions PDF By ScholarHat.pdf
PPTX
Python for Beginners(v1)
PPTX
PYTHON PPT.pptx python is very useful for day to day life
advanced python for those who have beginner level experience with python
Advanced Python after beginner python for intermediate learners
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
Python - Data Collection
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
Lecture 09.pptx
Python Revision Tour.pptx class 12 python notes
PRESENTATION ON STRING, LISTS AND TUPLES IN PYTHON.pptx
Python slide.1
Chapter - 2.pptx
Python 3.x quick syntax guide
Introduction to python programming ( part-3 )
Tuple Operation and Tuple Assignment in Python.pdf
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Basic of Python- Hands on Session
Python Interview Questions PDF By ScholarHat.pdf
Python for Beginners(v1)
PYTHON PPT.pptx python is very useful for day to day life
Ad

Recently uploaded (20)

PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
Cell Types and Its function , kingdom of life
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Insiders guide to clinical Medicine.pdf
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
Pre independence Education in Inndia.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Institutional Correction lecture only . . .
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Cell Types and Its function , kingdom of life
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Anesthesia in Laparoscopic Surgery in India
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Supply Chain Operations Speaking Notes -ICLT Program
Renaissance Architecture: A Journey from Faith to Humanism
Insiders guide to clinical Medicine.pdf
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
102 student loan defaulters named and shamed – Is someone you know on the list?
2.FourierTransform-ShortQuestionswithAnswers.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
01-Introduction-to-Information-Management.pdf
Pre independence Education in Inndia.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Institutional Correction lecture only . . .
Week 4 Term 3 Study Techniques revisited.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF

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.