Python If Else Statement
The if else statement is used to execute one of two statements based on the condition.
Syntax of If Else Statement
if condition: block else: block
In this, if the expression within the if statement is true, then the statements within the if are executed otherwise the statements within the else are executed. The condition is a boolean expression that determines whether or not the if block or the else block will be executed, A colon (:) must follow the condition.
Example of If Else Statement
>>> x = 10 >>> if(x > 10): print("x is greater than 10") else: print("x is less than 10") x is less than 10 >>> y = 20 >>> if(y == 20): print("y is equal to 20") else: print("y is not equal to 20") y is equal to 20