Python if else

In this article, we will show you Python if else statement with examples.

The if..else statement evaluates test expression and will execute the body of if only when the test condition is True.

If the condition is False, the body of else is executed. Indentation is used to separate the blocks.

Python if else statement flow diagram:

Python if else
Python if else syntax:

if test expression: Body of if else: Body of else

Python if else statement examples:

Example 1: Find the given number is even or odd using Python if else statement.

x= int(input("Enter a number :")) if x%2==0: print("Even number", x) print("Thank you") else: print("Odd number",x) print("Good Bye")

Python if else