SlideShare a Scribd company logo
2
Most read
3
Most read
17
Most read
Flow Control & Statements
Python control structures
 According to the structure theorem, any computer
program can be written using the basic control
structures .
 A control structure (or flow of control) is a block of
programming that analyses variables and
chooses a direction in which to go based on given
parameters. In simple sentence, a control
structure is just a decision that the computer
makes. So, it is the basic decision-making
process
Flow of control
Flow of control through any given program is
implemented with three basic types of control
structures:
 Sequential,
 Selection
 Repetition
Selection
 Python if statements
Python if..else statements
 The else statement is to specify a block of code
to be executed, if the condition in the if statement
is false. Thus, the else clause ensures that a
sequence of statements is executed.
if..elif..else statements
Python Loop / Iteration
Statements
 Loops are one of the most important features in
computer programming languages . As the
name suggests is the process that get repeated
again and again
Every loop has 3 parts:
 Initialization
 Condition
 Updation
Iteration Statements
What is for loop in Python?
 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.
Syntax of for Loop
for val in sequence:
Body 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.
Examples :
 print(range(10))
 Print(list(range(10))
 print(list(range(2, 8)))
 print(list(range(2, 20, 3)))
for loop with else
 A for loop can have an optional else block as well.
The else part is executed if the items in the
sequence used in for loop exhausts.
digits = [0, 1, 5]
for i in digits:
print(i)
else:
print("No items left.")
What is while loop in Python?
 The while loop in Python is used to iterate over a
block of code as long as the test expression
(condition) is true.
Python break and continue
 In Python, break and continue statements can alter
the flow of a normal loop.
 Loops iterate over a block of code until the test
expression is false, but sometimes we wish to
terminate the current iteration or even the whole loop
without checking test expression.
 The break statement terminates the loop containing it.
Control of the program flows to the statement
immediately after the body of the loop.
 The continue statement is used to skip the rest of the
code inside a loop for the current iteration only. Loop
does not terminate but continues on with the next
iteration.
Python break statement
Syntax of break
break
The working of break statement in for
loop and while loop is shown below.
Python continue statement
The working of continue statement in
for and while loop is shown below.
Ad

Recommended

Python programming : Control statements
Python programming : Control statements
Emertxe Information Technologies Pvt Ltd
 
Flow of Control
Flow of Control
Praveen M Jigajinni
 
Regular expressions-Theory of computation
Regular expressions-Theory of computation
Bipul Roy Bpl
 
Regular expressions in Python
Regular expressions in Python
Sujith Kumar
 
Variables & Data Types In Python | Edureka
Variables & Data Types In Python | Edureka
Edureka!
 
Regular expressions
Regular expressions
Ratnakar Mikkili
 
Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder
Vishvesh Jasani
 
Modular programming
Modular programming
Mohanlal Sukhadia University (MLSU)
 
File handling in Python
File handling in Python
Megha V
 
RECURSION IN C
RECURSION IN C
v_jk
 
Operators and expressions in c language
Operators and expressions in c language
tanmaymodi4
 
String Manipulation in Python
String Manipulation in Python
Pooja B S
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler Design
Akhil Kaushik
 
Python Control structures
Python Control structures
Siddique Ibrahim
 
Functions in C
Functions in C
Kamal Acharya
 
Python tuple
Python tuple
Mohammed Sikander
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design
MAHASREEM
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compiler
Iffat Anjum
 
Control Structures in Python
Control Structures in Python
Sumit Satam
 
C if else
C if else
Ritwik Das
 
Operators in python
Operators in python
Prabhakaran V M
 
Basic data types in python
Basic data types in python
sunilchute1
 
Python Exception Handling
Python Exception Handling
Megha V
 
Control statements in c
Control statements in c
Sathish Narayanan
 
Python dictionary
Python dictionary
Mohammed Sikander
 
Python list
Python list
Mohammed Sikander
 
Introduction to Python
Introduction to Python
Nowell Strite
 
Arrays in python
Arrays in python
moazamali28
 
ppt python notes list tuple data types ope
ppt python notes list tuple data types ope
SukhpreetSingh519414
 
Python session3
Python session3
Aswin Krishnamoorthy
 

More Related Content

What's hot (20)

File handling in Python
File handling in Python
Megha V
 
RECURSION IN C
RECURSION IN C
v_jk
 
Operators and expressions in c language
Operators and expressions in c language
tanmaymodi4
 
String Manipulation in Python
String Manipulation in Python
Pooja B S
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler Design
Akhil Kaushik
 
Python Control structures
Python Control structures
Siddique Ibrahim
 
Functions in C
Functions in C
Kamal Acharya
 
Python tuple
Python tuple
Mohammed Sikander
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design
MAHASREEM
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compiler
Iffat Anjum
 
Control Structures in Python
Control Structures in Python
Sumit Satam
 
C if else
C if else
Ritwik Das
 
Operators in python
Operators in python
Prabhakaran V M
 
Basic data types in python
Basic data types in python
sunilchute1
 
Python Exception Handling
Python Exception Handling
Megha V
 
Control statements in c
Control statements in c
Sathish Narayanan
 
Python dictionary
Python dictionary
Mohammed Sikander
 
Python list
Python list
Mohammed Sikander
 
Introduction to Python
Introduction to Python
Nowell Strite
 
Arrays in python
Arrays in python
moazamali28
 
File handling in Python
File handling in Python
Megha V
 
RECURSION IN C
RECURSION IN C
v_jk
 
Operators and expressions in c language
Operators and expressions in c language
tanmaymodi4
 
String Manipulation in Python
String Manipulation in Python
Pooja B S
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler Design
Akhil Kaushik
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design
MAHASREEM
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compiler
Iffat Anjum
 
Control Structures in Python
Control Structures in Python
Sumit Satam
 
Basic data types in python
Basic data types in python
sunilchute1
 
Python Exception Handling
Python Exception Handling
Megha V
 
Introduction to Python
Introduction to Python
Nowell Strite
 
Arrays in python
Arrays in python
moazamali28
 

Similar to Types of Statements in Python Programming Language (20)

ppt python notes list tuple data types ope
ppt python notes list tuple data types ope
SukhpreetSingh519414
 
Python session3
Python session3
Aswin Krishnamoorthy
 
Control structures pyhton
Control structures pyhton
Prakash Jayaraman
 
E-Notes_3721_Content_Document_20250107032537PM.pdf
E-Notes_3721_Content_Document_20250107032537PM.pdf
aayushihirpara297
 
ch2 Python flow control.pdf
ch2 Python flow control.pdf
RanjanaThakuria1
 
if else python.pdf
if else python.pdf
Gshs6
 
Chap05
Chap05
Terry Yoast
 
Ch-4.pdf
Ch-4.pdf
R.K.College of engg & Tech
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2
Syed Farjad Zia Zaidi
 
Ch05
Ch05
Arriz San Juan
 
Control flow statements in java web applications
Control flow statements in java web applications
RajithKarunarathne1
 
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...
jaychoudhary37
 
Programming in Arduino (Part 2)
Programming in Arduino (Part 2)
Niket Chandrawanshi
 
PYTHON FULL TUTORIAL WITH PROGRAMMS
PYTHON FULL TUTORIAL WITH PROGRAMMS
Aniruddha Paul
 
com.pptx
com.pptx
PriyadharshanBobby
 
C++ chapter 4
C++ chapter 4
SHRIRANG PINJARKAR
 
Android Application Development - Level 3
Android Application Development - Level 3
Isham Rashik
 
Unit - 2 CAP.pptx
Unit - 2 CAP.pptx
malekaanjum1
 
ceng4315636732530_1245235week_06_0.7.pdf
ceng4315636732530_1245235week_06_0.7.pdf
eagac2004
 
FLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHON
vikram mahendra
 
ppt python notes list tuple data types ope
ppt python notes list tuple data types ope
SukhpreetSingh519414
 
E-Notes_3721_Content_Document_20250107032537PM.pdf
E-Notes_3721_Content_Document_20250107032537PM.pdf
aayushihirpara297
 
ch2 Python flow control.pdf
ch2 Python flow control.pdf
RanjanaThakuria1
 
if else python.pdf
if else python.pdf
Gshs6
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2
Syed Farjad Zia Zaidi
 
Control flow statements in java web applications
Control flow statements in java web applications
RajithKarunarathne1
 
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...
jaychoudhary37
 
PYTHON FULL TUTORIAL WITH PROGRAMMS
PYTHON FULL TUTORIAL WITH PROGRAMMS
Aniruddha Paul
 
Android Application Development - Level 3
Android Application Development - Level 3
Isham Rashik
 
ceng4315636732530_1245235week_06_0.7.pdf
ceng4315636732530_1245235week_06_0.7.pdf
eagac2004
 
FLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHON
vikram mahendra
 
Ad

Recently uploaded (20)

“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
Edge AI and Vision Alliance
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Impelsys Inc.
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
Edge AI and Vision Alliance
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Impelsys Inc.
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Ad

Types of Statements in Python Programming Language

  • 1. Flow Control & Statements
  • 2. Python control structures  According to the structure theorem, any computer program can be written using the basic control structures .  A control structure (or flow of control) is a block of programming that analyses variables and chooses a direction in which to go based on given parameters. In simple sentence, a control structure is just a decision that the computer makes. So, it is the basic decision-making process
  • 3. Flow of control Flow of control through any given program is implemented with three basic types of control structures:  Sequential,  Selection  Repetition
  • 5. Python if..else statements  The else statement is to specify a block of code to be executed, if the condition in the if statement is false. Thus, the else clause ensures that a sequence of statements is executed.
  • 7. Python Loop / Iteration Statements  Loops are one of the most important features in computer programming languages . As the name suggests is the process that get repeated again and again Every loop has 3 parts:  Initialization  Condition  Updation
  • 9. What is for loop in Python?  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. Syntax of for Loop for val in sequence: Body of for loop
  • 10. 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. Examples :  print(range(10))  Print(list(range(10))  print(list(range(2, 8)))  print(list(range(2, 20, 3)))
  • 11. for loop with else  A for loop can have an optional else block as well. The else part is executed if the items in the sequence used in for loop exhausts. digits = [0, 1, 5] for i in digits: print(i) else: print("No items left.")
  • 12. What is while loop in Python?  The while loop in Python is used to iterate over a block of code as long as the test expression (condition) is true.
  • 13. Python break and continue  In Python, break and continue statements can alter the flow of a normal loop.  Loops iterate over a block of code until the test expression is false, but sometimes we wish to terminate the current iteration or even the whole loop without checking test expression.  The break statement terminates the loop containing it. Control of the program flows to the statement immediately after the body of the loop.  The continue statement is used to skip the rest of the code inside a loop for the current iteration only. Loop does not terminate but continues on with the next iteration.
  • 15. The working of break statement in for loop and while loop is shown below.
  • 17. The working of continue statement in for and while loop is shown below.