Introduction
In this article, I will explain conditional statements in Python. Conditional statements are also called decision-making statements. We use those statements while we want to execute a block of code when the given condition is true or false.
Type of condition statement in Python:
-
If statement.
-
If Else statement.
-
Elif statement.
-
Nested if statement.
-
Nested if else statement.
If statement
If statement is most usually used as a conditional statement.
Syntax
- if(condition):
- {
- #if statement
- }
Example
Program for if statement,
- a = 10
- b = 20
- if a<b:
- print("a is less than b")
Output

If else statement
If else is a conditional statement. The statement itself says that if a given condition is true or false. True means executing the “if” statement to the output. False means executing the “else” statement to the output.
Syntax
- if(condition):
- {
- # if statement
- }
- else:
- {
- # else statement
- }
Example
Program for if else statement,
- a = 10
- b = 20
- if a==b:
- print("a and b are equal")
- else:
- print("a and b are not equal")
Output

Elif statement
Elif is a shortcut of else if condition statements. In Python one or more conditions are used in the elif statement.
Syntax
- if(condition):
- {
- # if statement
- }
- elif(condition):
- {
- # elif statement
- }
- else:
- {
- # else statement
- }



Koshila SenadhiraPosted Dec 1, 2022, 11:19 AM
Interesting Article!
Dipa MehtaPosted Mar 6, 2020, 7:52 AM
Good one Surya. Keep it up. ..