
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to use nested if statement in Python?
In programming the term nesting is used when conditional statements appear one inside other. In Python, new if statement can be nested in if as well as else block. A you must be knowing, each if block has increasing level of indentation. Hence in case of nested if condition, indent level of inner block will increase from outer block. A general syntax of nested if can be as below −
if expr1==True: if expr2==True: #this block will be executed when expr1 and expr2 are true else: #this block if expr is true but expr2 is false else: if expr3==True: #if expr1 is false and expr3 is true else: #when expr1 and expr3 are false
- Related Articles
- What is the ‘nested if’ statement in Java and how to use it?
- How to use IF statement in MySQL using Python?
- How to use nested loops in Python?
- How to use multiple conditions in one if statement in Python?
- Java nested if statement example
- How to use if...else statement at the command line in Python?
- Explain Nested if-else statement in C language
- How to use continue statement in Python loop?
- How do we use nested if statements in C#?
- How to optimize nested if...elif...else in Python?
- How to use else statement with Loops in Python?
- How to use OR condition in a JavaScript IF statement?
- Can we use break statement in a Python if clause?
- Can we use continue statement in a Python if clause?
- Can we use pass statement in a Python if clause?

Advertisements