

- 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
What is the syntax of Python if...elif...else statement?
In Python program if..elif..else construct is used if it has ;arge number of logical expressions to be evaluated so that earlier expressions turn out to be true. If you use nested if - else structure, then indent level of subsequent blocks goes on increasing and program becomes difficult to read. This is where elif is handy. Each block of statements under elif is executed if earlier condition false. Last else block is executed when all previous logical expressions fail. All the blocks have same level of indent.
if expression1==True: statement(s) elif expression2==True: statement(s) elif expression3==True: statement(s) else: statement(s)
- Related Questions & Answers
- What is basic syntax of Python if...else statement?
- What is correct syntax of Python if statement?
- What is the if...else statement in JavaScript?
- What is if...else if... statement in JavaScript?
- How to optimize nested if...elif...else in Python?
- Java if-else statement
- What is the resemblance of COALESCE() function with IF-THEN-ELSE statement?
- What is the ‘if...else if...else’ statement in Java and how to use it?
- Java if-else-if ladder statement
- Where to put comments in an if...elif..else construct?
- Java if-then-else statement
- IF ELSE statement in a MySQL Statement?
- How to indent an if...else statement in Python?
- How to use #if..#elif…#else…#endif directives in C#?
- Explain if-else statement in C language
Advertisements