Python if else
There comes situations in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations arises in programming also where we need to make some decisions and based on these decisions we will execute the next block of code.
Decision making statements in programming languages decides the direction of flow of program execution. Decision making statements available in python are:
- if statement
- if..else statements
- nested if statements
- if elif ladder
- Short Hand if statements
- Short Hand if else statements
if- else:
The if-else statement provides an else block combined with the if statement which is executed in the false case of the condition.
If the condition is true, then the if-block is executed. Otherwise, the else-block is executed.
Syntax:
if (condition):
# Executes this block if
# condition is true
else:
# Executes this block if
# condition is false
Flow Chart:-
# python program to illustrate If else statement
Output:
i is greater than 15
i'm in else Block
i'm not in if and not in else Block
Thanks! I hope this article is helpful for you :)