

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- Java nested if statement example
- How to use IF statement in MySQL using Python?
- What is the ‘nested if’ statement in Java and how to use it?
- How to use multiple conditions in one if statement in Python?
- Explain Nested if-else statement in C language
- How to use nested loops in Python?
- How to use if...else statement at the command line in Python?
- How do we use nested if statements in C#?
- 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?
- How to optimize nested if...elif...else in Python?
- How to use continue statement in Python loop?
- How to handle python exception inside if statement?
Advertisements