Learning Objectives
By the end of this lesson, you will be able to:
Describe expressions
Illustrate conditional statements
Explain loops
Describe functions
Conditional Statements and Functions
Conditional Expressions
Conditional expressions are used for comparison. Conditional statements supported by Python
are:
Equal
a==b
Not equal
a!=b
Less than
a<b
Less than or equal
a<=b
Greater than
a>b
Greater than or
equal
a>=b
Membership Expressions
Membership expressions are used to validate the membership of a value. It tests for
membership in a sequence, such as strings, lists, or tuples. The different membership
expressions in Python are:
Expression:
▪ Checks for equality
▪ Compares members
Conditional Statements
if, elif, else
Conditional statements execute a group of statements only based on some condition. In
Python, if ,elif, and else are the conditional keyword statements in use.
if: Executes a set of statements only if the condition is true otherwise, statement is
skipped.
Condition
Indentation
matters
if, elif, else
elif: elif or else if is to check multiple conditions.
else: If the condition is not true under if or elif, then the code jumps to else condition.
Jumps to
else
Loops
for Loop
Loops execute a group of statements as long as a condition is True. Python has two basic loops: for
loop and while loop.
for loop: This is also called iterative loop in Python. For loops can iterate over a sequence of
numbers using the "range" and "xrange" functions.
Range function to
set sequence limits
for iteration
Sequence Iteration Using for Loop
String
iteration
using for loop
List iteration
using for
loop
Tuple iteration
using for loop
Sequence IterationUsingfor Loop
dictionary
iteration using
for loop
Sets iteration
using for
loop
Sequence IterationUsingfor Loop
Sequence IterationUsingfor Loop
while Loop
while loop: while loops execute a set of statements as long as a condition is true.
Functions
Functions
A function is a block of code which only runs when it is called.
Defining
function
Passing
variables
Function
Call
Functions
A return statement ends the execution of the function call and returns the result. It is the value
of the expression following the return keyword to the caller.
In-Built Functions in Python
Python has a large library of in-built functions. Some of them are discussed here.
eval(): It evaluates the passed string as a Python expression and returns the result.
lamba(): helps to create one-line functions in Python.
In-Built Functions in Python
map() function returns a list of results after applying the given function to each item of a given
iterable.
• map(fun, iter) : Syntax
• fun : It is a function to which map passes each element of given iterable.
• iter : It is an iterable which is to be mapped.
• You can pass one or more iterable to the map() function.
In-Built Functions in Python
round() function rounds a number to give precision in decimal digits. If the number of decimal
places has not been specified, the decimal number is rounded off to a whole number.
Rounds number
to 2 decimal
places
In-Built Functions in Python
all() function returns false if any one of the elements of the iterable is zero and true if all the
elements of the iterable are nonzero.
Returns True
as non-zero
sequence
Returns False as
zero is present
in sequence
Knowledge Check
“a” is “apple”, will give output
as:
a. a
b. False
c. True
d. Will show error
Knowledge
Check
1
“a” is “apple”, will give output
as:
a. a
b. False
c. True
d. Will show error
Knowledge
Check
1
The correct answer is b
“is “ is a membership operator in Python which returns ‘True’ for exact
value.
a.
b.
Knowledge
Check
2
Let a=“XY“ then the expression: for i in
a:
print(a,end="t")
will give output
as:
X
Y
XY
X
Y
c. X
Y
d. XY
XY
a.
b.
Let a=“XY“ then the expression: for i in
a:
print(a,end="t")
will give output
as:
X
Y
XY
X
Y
c. X Y
d. XY
XY
Knowledge
Check
2
The correct answer is d
for loop will iterate the sequence two times and ends each iteration with a
tab.
Knowledge
Check
3
eval() function evaluates:
a. Expression passed as a string
b. Expression only if it contains digits
c. Expression containing digits and strings
d. Expression to sort the strings
eval() function evaluates:
Knowledge
Check
3
The correct answer is a
eval() evaluates the expression passed as a string and returns the
result.
a. Expression passed as a string
b. Expression only if it contains digits
c. Expression containing digits and strings
d. Expression to sort the strings
The output of: max(False,-4,-1)
a. -1
b. True
c. False
d. -4
Knowledge
Check
4
The output of: max(False,-4,-1)
a. -1
b. True
c. False
d. -4
Knowledge
Check
4
The correct answer is c
The function max() is being used to find the maximum value from -4, -1, and false. Since, false amounts to the
value zero, Hence, False is the right answer.
Key Takeaways
Conditional statements use conditional operators.
For loop is an iterative loop in Python.
Functions limit the use of loops.

More Related Content

PPT
hlukj6;lukm,t.mnjhgjukryopkiu;lyk y2.ppt
PPT
Py-Slides-2 (1).ppt
PPT
Py-Slides-2.ppt
PPT
Py-Slides-2.ppt
PPTX
Unit - 2 CAP.pptx
PPTX
UNIT – 3.pptx for first year engineering
PDF
Pythonintro
PDF
Python Unit 3 - Control Flow and Functions
hlukj6;lukm,t.mnjhgjukryopkiu;lyk y2.ppt
Py-Slides-2 (1).ppt
Py-Slides-2.ppt
Py-Slides-2.ppt
Unit - 2 CAP.pptx
UNIT – 3.pptx for first year engineering
Pythonintro
Python Unit 3 - Control Flow and Functions

Similar to Python Conditional_Statements_and_Functions (20)

PPTX
Python programming language introduction unit
PPTX
Python Session - 4
PPTX
Python Revision Tour.pptx class 12 python notes
PPTX
TN 12 computer Science - ppt CHAPTER-6.pptx
PPT
PPT3-CONDITIONAL STATEMENT LOOPS DICTIONARY FUNCTIONS.ppt
PPT
python operators.ppt
PPT
ppt3-conditionalstatementloopsdictionaryfunctions-240731050730-455ba0fa.ppt
PPTX
python fudmentalsYYour score increaseases
PPTX
Introduction To Python.pptx
PPTX
Python basics
PPT
Phyton Learning extracts
PPTX
MODULE. .pptx
PPTX
IMP PPT- Python programming fundamentals.pptx
PPTX
Chapter - 3.pptx
PDF
Python revision tour i
PPT
python
PPTX
Week 2.pptx
PPTX
INTRODUCTION TO PYTHON PROGRMMING AND FUNCTIONS
PPTX
Introduction to Python Part-1
PDF
Unit 1- Part-2-Control and Loop Statements.pdf
Python programming language introduction unit
Python Session - 4
Python Revision Tour.pptx class 12 python notes
TN 12 computer Science - ppt CHAPTER-6.pptx
PPT3-CONDITIONAL STATEMENT LOOPS DICTIONARY FUNCTIONS.ppt
python operators.ppt
ppt3-conditionalstatementloopsdictionaryfunctions-240731050730-455ba0fa.ppt
python fudmentalsYYour score increaseases
Introduction To Python.pptx
Python basics
Phyton Learning extracts
MODULE. .pptx
IMP PPT- Python programming fundamentals.pptx
Chapter - 3.pptx
Python revision tour i
python
Week 2.pptx
INTRODUCTION TO PYTHON PROGRMMING AND FUNCTIONS
Introduction to Python Part-1
Unit 1- Part-2-Control and Loop Statements.pdf
Ad

More from Puneet Kumar Bhatia (MBA, ITIL V3 Certified) (20)

PPTX
Web programming using python frameworks.
PPTX
Azure Fubdamentals (Az-900) presentation.
PPTX
Azure - Basic concepts and overview.pptx
PPTX
Cloud Computing basics - an overview.pptx
PPTX
Ansible as configuration management tool for devops
PPTX
Microsoft Azure - Basic concepts presentation
PPTX
Introduction to the Nexus tool for DevOps
PPTX
Introduction to Monitoring Tools for DevOps
PPTX
Introduction to Monitoring Tools for DevOps
PPT
Introduction to Devops and its applications
PPTX
Container Orchestration using kubernetes
PPTX
Containerization using docker and its applications
PPTX
Containerization using docker and its applications
PDF
Java Microservices_64 Hours_Day wise plan (002).pdf
PDF
Java Microservices_64 Hours_Day wise plan (002).pdf
PPTX
Changing paradigm in job market
PDF
Web programming using python frameworks.
Azure Fubdamentals (Az-900) presentation.
Azure - Basic concepts and overview.pptx
Cloud Computing basics - an overview.pptx
Ansible as configuration management tool for devops
Microsoft Azure - Basic concepts presentation
Introduction to the Nexus tool for DevOps
Introduction to Monitoring Tools for DevOps
Introduction to Monitoring Tools for DevOps
Introduction to Devops and its applications
Container Orchestration using kubernetes
Containerization using docker and its applications
Containerization using docker and its applications
Java Microservices_64 Hours_Day wise plan (002).pdf
Java Microservices_64 Hours_Day wise plan (002).pdf
Changing paradigm in job market
Ad

Recently uploaded (20)

PDF
Topaz Photo AI Crack New Download (Latest 2025)
PDF
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
PDF
AI/ML Infra Meetup | LLM Agents and Implementation Challenges
PPTX
Python is a high-level, interpreted programming language
PDF
E-Commerce Website Development Companyin india
PPTX
GSA Content Generator Crack (2025 Latest)
PDF
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
PDF
Internet Download Manager IDM Crack powerful download accelerator New Version...
PDF
EaseUS PDF Editor Pro 6.2.0.2 Crack with License Key 2025
PDF
Guide to Food Delivery App Development.pdf
DOC
UTEP毕业证学历认证,宾夕法尼亚克拉里恩大学毕业证未毕业
PDF
AI Guide for Business Growth - Arna Softech
PPTX
Cybersecurity-and-Fraud-Protecting-Your-Digital-Life.pptx
PDF
MCP Security Tutorial - Beginner to Advanced
PPTX
CNN LeNet5 Architecture: Neural Networks
PDF
Visual explanation of Dijkstra's Algorithm using Python
PPTX
Trending Python Topics for Data Visualization in 2025
PDF
CCleaner 6.39.11548 Crack 2025 License Key
PDF
AI-Powered Fuzz Testing: The Future of QA
PDF
Introduction to Ragic - #1 No Code Tool For Digitalizing Your Business Proces...
Topaz Photo AI Crack New Download (Latest 2025)
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
AI/ML Infra Meetup | LLM Agents and Implementation Challenges
Python is a high-level, interpreted programming language
E-Commerce Website Development Companyin india
GSA Content Generator Crack (2025 Latest)
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
Internet Download Manager IDM Crack powerful download accelerator New Version...
EaseUS PDF Editor Pro 6.2.0.2 Crack with License Key 2025
Guide to Food Delivery App Development.pdf
UTEP毕业证学历认证,宾夕法尼亚克拉里恩大学毕业证未毕业
AI Guide for Business Growth - Arna Softech
Cybersecurity-and-Fraud-Protecting-Your-Digital-Life.pptx
MCP Security Tutorial - Beginner to Advanced
CNN LeNet5 Architecture: Neural Networks
Visual explanation of Dijkstra's Algorithm using Python
Trending Python Topics for Data Visualization in 2025
CCleaner 6.39.11548 Crack 2025 License Key
AI-Powered Fuzz Testing: The Future of QA
Introduction to Ragic - #1 No Code Tool For Digitalizing Your Business Proces...

Python Conditional_Statements_and_Functions

  • 1. Learning Objectives By the end of this lesson, you will be able to: Describe expressions Illustrate conditional statements Explain loops Describe functions
  • 3. Conditional Expressions Conditional expressions are used for comparison. Conditional statements supported by Python are: Equal a==b Not equal a!=b Less than a<b Less than or equal a<=b Greater than a>b Greater than or equal a>=b
  • 4. Membership Expressions Membership expressions are used to validate the membership of a value. It tests for membership in a sequence, such as strings, lists, or tuples. The different membership expressions in Python are: Expression: ▪ Checks for equality ▪ Compares members
  • 6. if, elif, else Conditional statements execute a group of statements only based on some condition. In Python, if ,elif, and else are the conditional keyword statements in use. if: Executes a set of statements only if the condition is true otherwise, statement is skipped. Condition Indentation matters
  • 7. if, elif, else elif: elif or else if is to check multiple conditions. else: If the condition is not true under if or elif, then the code jumps to else condition. Jumps to else
  • 9. for Loop Loops execute a group of statements as long as a condition is True. Python has two basic loops: for loop and while loop. for loop: This is also called iterative loop in Python. For loops can iterate over a sequence of numbers using the "range" and "xrange" functions. Range function to set sequence limits for iteration
  • 10. Sequence Iteration Using for Loop String iteration using for loop
  • 11. List iteration using for loop Tuple iteration using for loop Sequence IterationUsingfor Loop
  • 12. dictionary iteration using for loop Sets iteration using for loop Sequence IterationUsingfor Loop
  • 14. while Loop while loop: while loops execute a set of statements as long as a condition is true.
  • 16. Functions A function is a block of code which only runs when it is called. Defining function Passing variables Function Call
  • 17. Functions A return statement ends the execution of the function call and returns the result. It is the value of the expression following the return keyword to the caller.
  • 18. In-Built Functions in Python Python has a large library of in-built functions. Some of them are discussed here. eval(): It evaluates the passed string as a Python expression and returns the result. lamba(): helps to create one-line functions in Python.
  • 19. In-Built Functions in Python map() function returns a list of results after applying the given function to each item of a given iterable. • map(fun, iter) : Syntax • fun : It is a function to which map passes each element of given iterable. • iter : It is an iterable which is to be mapped. • You can pass one or more iterable to the map() function.
  • 20. In-Built Functions in Python round() function rounds a number to give precision in decimal digits. If the number of decimal places has not been specified, the decimal number is rounded off to a whole number. Rounds number to 2 decimal places
  • 21. In-Built Functions in Python all() function returns false if any one of the elements of the iterable is zero and true if all the elements of the iterable are nonzero. Returns True as non-zero sequence Returns False as zero is present in sequence
  • 23. “a” is “apple”, will give output as: a. a b. False c. True d. Will show error Knowledge Check 1
  • 24. “a” is “apple”, will give output as: a. a b. False c. True d. Will show error Knowledge Check 1 The correct answer is b “is “ is a membership operator in Python which returns ‘True’ for exact value.
  • 25. a. b. Knowledge Check 2 Let a=“XY“ then the expression: for i in a: print(a,end="t") will give output as: X Y XY X Y c. X Y d. XY XY
  • 26. a. b. Let a=“XY“ then the expression: for i in a: print(a,end="t") will give output as: X Y XY X Y c. X Y d. XY XY Knowledge Check 2 The correct answer is d for loop will iterate the sequence two times and ends each iteration with a tab.
  • 27. Knowledge Check 3 eval() function evaluates: a. Expression passed as a string b. Expression only if it contains digits c. Expression containing digits and strings d. Expression to sort the strings
  • 28. eval() function evaluates: Knowledge Check 3 The correct answer is a eval() evaluates the expression passed as a string and returns the result. a. Expression passed as a string b. Expression only if it contains digits c. Expression containing digits and strings d. Expression to sort the strings
  • 29. The output of: max(False,-4,-1) a. -1 b. True c. False d. -4 Knowledge Check 4
  • 30. The output of: max(False,-4,-1) a. -1 b. True c. False d. -4 Knowledge Check 4 The correct answer is c The function max() is being used to find the maximum value from -4, -1, and false. Since, false amounts to the value zero, Hence, False is the right answer.
  • 31. Key Takeaways Conditional statements use conditional operators. For loop is an iterative loop in Python. Functions limit the use of loops.