- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 basic syntax of Python if...else statement?
In Python, the conditional statement if can have an optional else clause. The indented block after if statement is executed when logical expression in front of if is true. If an alternative action is sought to be taken by program if the expression is false, it is given as another indented block after else. The usage is described below −
if expr==True: #stmt1 #stmt2 else: #stmt3 #stmt4
Here first block containing stmt1 and stmt2 will be executed if expr is true. Whereas second block containing stmt3 and stmt4 will be executed if expr is false
- Related Articles
- What is the syntax of Python if...elif...else statement?
- What is correct syntax of Python if statement?
- What is basic syntax of Python for Loops?
- What is if...else if... statement in JavaScript?
- What is the if...else statement in JavaScript?
- What is the ‘if...else if...else’ statement in Java and how to use it?
- Java if-else statement
- What is the basic syntax to access Python Dictionary Elements?
- Java if-else-if ladder statement
- IF ELSE statement in a MySQL Statement?
- What is the resemblance of COALESCE() function with IF-THEN-ELSE statement?
- Java if-then-else statement
- How to indent an if...else statement in Python?
- Explain if-else statement in C language
- What is the ‘if else’ statement in Java and how to use it?

Advertisements