Python if…else Statement

In this tutorial you will learn about the Python if…else Statement and its application with practical example.

Python if Statement

Block of statement executed only when a specified condition is true.

Syntax:-

Example:-

Output:-

Python if…else Statement

When we want to execute some block of code if a condition is true and another block of code if a condition is false, In such a case we use if….else statement.

Syntax:-

Example:-

Output:-

Python if…elif…else Statement

The if….elif…else statement is used to select one of among several blocks of code to be executed.

Syntax:-

Example:-

Output:-

Python Nested if statements

When there is an if statement inside another if statement then it is known as nested if else.

Syntax:-

Single Statement Condition

Example:-

Output:-

In this tutorial we have learn about the Python if…else Statement and its application with practical example. I hope you will like this tutorial.