PART 4
IF ELSE STATEMENT IN PYTHON
• WANT TO LEARN PYTHON PROGRAMMING? (SUBTITLES)
• SUBSCRIBE
• TELEGRAM – FreeCodeSchool
• Twitter – shivammitra4
• LinkedIn – shivammitra
• Link in description
Checkout the Python tutorial playlist
AGENDA
• SIMPLE IF ELSE STATEMENT
• CONDITIONAL TESTS
• AND, OR OPERATOR
• ADVANCED IF ELSE STATEMENTS
EXAMPLE
• Example 1
• number = 2
• If number is odd, print “odd number”
• If number is even, print “even number”
• Example 2
• name = ‘Shivam’
• If name is ‘Shivam’, print it in capital letters
• Otherwise, print as it is
CONDITIONAL TESTS
• Conditional test
• If test is true, execute the code under if statement
• If test is false, ignore the code under if statement and move forward
CHECK FOR EQUALITY
• Equality operator returns True if value on left and right side matches.
Otherwise, False.
• Assignment operator(=) vs Equality operator(==)
• Assignment -> Storing a value in a variable
• Equality operator -> Are the values equal on both the sides ?
IGNORING THE CASE WHEN CHECKING FOR
EQUALITY
• Gmail – freecodeschool vs FreeCodeSchool (@gmail.com)
CHECKING FOR INEQUALITY
• If two values doesn’t match, True
• If two value matches, False
NUMERICAL COMPARISONS
PART 4 - Python Tutorial | If Else In Python With Examples
PART 4 - Python Tutorial | If Else In Python With Examples
CHECKING MULTIPLE CONDITIONS
• you might need two conditions to be True to take an action
• you might be satisfied with just one condition being True
• Keywords – and, or
USING AND TO CHECK MULTIPLE CONDITIONS
• Multiple tests
• If all test passes, return True
• If even one of the test fails, return False
• Checking happens in order
• If one test returns False, further checking doesn’t happen
• More than 2 tests are also possible
using parentheses
PART 4 - Python Tutorial | If Else In Python With Examples
USING OR TO CHECK MULTIPLE CONDITIONS
• Multiple tests
• If any one of the test passes, return True
• Go in order and stop when any test passes
• If all the test fails, return False
PART 4 - Python Tutorial | If Else In Python With Examples
CHECKING WHETHER A VALUS IS IN THE LIST
PART 4 - Python Tutorial | If Else In Python With Examples
CHECKING WHETHER A VALUE IS NOT IN THE
LIST
BOOLEAN EXPRESSIONS
• Another name for conditional statements
• A Boolean value is either True or False
IF STATEMENTS
SIMPLE IF STATEMENTS
PART 4 - Python Tutorial | If Else In Python With Examples
PART 4 - Python Tutorial | If Else In Python With Examples
PART 4 - Python Tutorial | If Else In Python With Examples
IF-ELSE STATEMENTS
PART 4 - Python Tutorial | If Else In Python With Examples
IF-ELIF-ELSE CHAIN
GRADING
• marks >= 90 and marks <= 100 – A
• marks >= 70 and marks < 90 – B
• marks >= 50 and marks < 70 – C
• marks >= 40 and marks < 50 – D
• Otherwise, F
PART 4 - Python Tutorial | If Else In Python With Examples
OMITTING THE ELSE BLOCK
TESTING MULTIPLE CONDITIONS
USING IF STATEMENTS WITH LISTS
• ODD EVEN EXAMPLE
• SEARCH A NAME EXAMPLE
CHECKING IF A LIST IS EMPTY
ASSIGNMENT
a = 2
b = 3
If a is greater than b, print “a > b”
If a is smaller than b, print “a < b”
If a is equal to b , print “a = b”
Note: a and b can take any values
WRITE SOME BASIC PROGRAMS IN PYTHON

More Related Content

PPTX
PART 3 - Python Tutorial | For Loop In Python With Examples
PPTX
Part 2 - Python Tutorial | Introduction to Lists
PPTX
PART 9 - Python Tutorial | While Loop In Python With Examples
PPTX
PART 10 - Python Tutorial | Functions In Python With Examples
PPTX
PART 7 - Python Tutorial | Dictionaries In Python With Examples
PPTX
PART 1 - Python Tutorial | Variables and Data Types in Python
PDF
List comprehensions
PPTX
Python 3 Programming Language
PART 3 - Python Tutorial | For Loop In Python With Examples
Part 2 - Python Tutorial | Introduction to Lists
PART 9 - Python Tutorial | While Loop In Python With Examples
PART 10 - Python Tutorial | Functions In Python With Examples
PART 7 - Python Tutorial | Dictionaries In Python With Examples
PART 1 - Python Tutorial | Variables and Data Types in Python
List comprehensions
Python 3 Programming Language

What's hot (20)

PPTX
Python basics
PPTX
List in Python
PDF
Python functions
PDF
Python made easy
PPTX
Functions in Python
PDF
Python recursion
PPTX
Looping Statements and Control Statements in Python
PPT
Bubble sort
PPTX
Stack_Application_Infix_Prefix.pptx
PPTX
Python-Inheritance.pptx
PPTX
Data structure by Digvijay
PPTX
Full Python in 20 slides
PPTX
Packages In Python Tutorial
PPTX
Polymorphism in Python
PPTX
Type casting
PDF
Python Basics | Python Tutorial | Edureka
PPTX
Data Structures in Python
PDF
Python Programming - VI. Classes and Objects
PPSX
Programming with Python
PDF
Set methods in python
Python basics
List in Python
Python functions
Python made easy
Functions in Python
Python recursion
Looping Statements and Control Statements in Python
Bubble sort
Stack_Application_Infix_Prefix.pptx
Python-Inheritance.pptx
Data structure by Digvijay
Full Python in 20 slides
Packages In Python Tutorial
Polymorphism in Python
Type casting
Python Basics | Python Tutorial | Edureka
Data Structures in Python
Python Programming - VI. Classes and Objects
Programming with Python
Set methods in python
Ad

Similar to PART 4 - Python Tutorial | If Else In Python With Examples (20)

PPTX
“Python” or “CPython” is written in C/C+
PPT
introduction to python in english presentation file
PPT
Chaptfffffuuer05.PPT
PDF
ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2
PDF
if else python.pdf
PPT
Introduction to Python Lesson Three_041313.ppt
PPTX
FLOWOFCONTROL-IF..ELSE PYTHON
PPT
python operators.ppt
PPT
PythonCourse_03_Conditionals.ppt Python introduction turorial for beginner.
PPTX
Introduction-to-Conditional-Statements-in-Python.pptx
PDF
23CSC101T PSPP python programming - UNIT 3.pdf
PDF
23CSC101T PSPP python program - UNIT 3.pdf
PPTX
Chapter 9 Conditional and Iterative Statements.pptx
PPTX
Brixton Library Technology Initiative Week1 Recap
PPTX
PYTHON BASICS CODING LANGUAGE GO TO.pptx
PPTX
Baabtra.com little coder chapter - 5
PPT
Py-Slides-2 (1).ppt
PPT
Py-Slides-2.ppt
PPT
Py-Slides-2.ppt
“Python” or “CPython” is written in C/C+
introduction to python in english presentation file
Chaptfffffuuer05.PPT
ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2
if else python.pdf
Introduction to Python Lesson Three_041313.ppt
FLOWOFCONTROL-IF..ELSE PYTHON
python operators.ppt
PythonCourse_03_Conditionals.ppt Python introduction turorial for beginner.
Introduction-to-Conditional-Statements-in-Python.pptx
23CSC101T PSPP python programming - UNIT 3.pdf
23CSC101T PSPP python program - UNIT 3.pdf
Chapter 9 Conditional and Iterative Statements.pptx
Brixton Library Technology Initiative Week1 Recap
PYTHON BASICS CODING LANGUAGE GO TO.pptx
Baabtra.com little coder chapter - 5
Py-Slides-2 (1).ppt
Py-Slides-2.ppt
Py-Slides-2.ppt
Ad

More from Shivam Mitra (15)

PPTX
Preparing for SRE Interviews
PPTX
PART 8 - Python Tutorial | User Input In Python With Examples
PPTX
PART 6 - Python Tutorial | Tuples In Python With Examples
PPTX
PART 0 - Python Tutorial | Why should you learn python
PPTX
Memory management in operating system | Paging | Virtual memory
PPTX
Process Synchronization in operating system | mutex | semaphore | race condition
PPTX
Process Scheduling Algorithms | Interviews | Operating system
PPTX
Threads in Operating System | Multithreading | Interprocess Communication
PPTX
Process management in operating system | process states | PCB | FORK() | Zomb...
PPTX
Introduction to operating system, system calls and interrupts
PPTX
What is Internet and How it Works
PPTX
OSI Model Layers and Internet Protocol Stack
PPTX
Basics of Stock Market
PPTX
Assets vs liability
PPTX
Pycricbuzz - a python library to fetch live cricket scores
Preparing for SRE Interviews
PART 8 - Python Tutorial | User Input In Python With Examples
PART 6 - Python Tutorial | Tuples In Python With Examples
PART 0 - Python Tutorial | Why should you learn python
Memory management in operating system | Paging | Virtual memory
Process Synchronization in operating system | mutex | semaphore | race condition
Process Scheduling Algorithms | Interviews | Operating system
Threads in Operating System | Multithreading | Interprocess Communication
Process management in operating system | process states | PCB | FORK() | Zomb...
Introduction to operating system, system calls and interrupts
What is Internet and How it Works
OSI Model Layers and Internet Protocol Stack
Basics of Stock Market
Assets vs liability
Pycricbuzz - a python library to fetch live cricket scores

Recently uploaded (20)

PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PDF
Environmental Education MCQ BD2EE - Share Source.pdf
PDF
semiconductor packaging in vlsi design fab
PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PDF
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 1).pdf
PDF
Mucosal Drug Delivery system_NDDS_BPHARMACY__SEM VII_PCI.pdf
PDF
LIFE & LIVING TRILOGY- PART (1) WHO ARE WE.pdf
PPTX
Virtual and Augmented Reality in Current Scenario
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PDF
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 2).pdf
PPTX
Education and Perspectives of Education.pptx
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
PDF
English Textual Question & Ans (12th Class).pdf
PDF
Race Reva University – Shaping Future Leaders in Artificial Intelligence
PDF
LEARNERS WITH ADDITIONAL NEEDS ProfEd Topic
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PDF
Skin Care and Cosmetic Ingredients Dictionary ( PDFDrive ).pdf
B.Sc. DS Unit 2 Software Engineering.pptx
Environmental Education MCQ BD2EE - Share Source.pdf
semiconductor packaging in vlsi design fab
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 1).pdf
Mucosal Drug Delivery system_NDDS_BPHARMACY__SEM VII_PCI.pdf
LIFE & LIVING TRILOGY- PART (1) WHO ARE WE.pdf
Virtual and Augmented Reality in Current Scenario
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 2).pdf
Education and Perspectives of Education.pptx
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
English Textual Question & Ans (12th Class).pdf
Race Reva University – Shaping Future Leaders in Artificial Intelligence
LEARNERS WITH ADDITIONAL NEEDS ProfEd Topic
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
Skin Care and Cosmetic Ingredients Dictionary ( PDFDrive ).pdf

PART 4 - Python Tutorial | If Else In Python With Examples