A conditional statement is a programming construct that allows a program to take a specific action based on the evaluation of a specific condition. In Python, if-else conditions are used to create conditional statements.
They execute different blocks of code depending on whether a certain condition is true or false. Conditional statements are useful for making decisions in your code based on different scenarios.
Python Logical Conditions
- Equal to ( a==b )
- Not Equal to ( a!=b )
- Grater than ( a>b)
- Grater than or Equal to ( a>=b)
- Less than ( a<b)
- Less than or Equal to ( a<=b )
1). if statement:
print("a is less than b")
In this example we have two variable a and b if condition a<b is true than code will be execute inside the if statement rather than no execution occur.
2). else statement:
print("a is less than b")
In this example we have two variables a and b if condition a<b is false than code will be execute inside the else statement.
3). elif statement:
If you want to apply multiple conditions checking the you can use elif statement.
print("a is less than b")
In this example we have two variable a and b if condition a<b is true than code will be execute inside the if statement and a>b than code will be execute inside the elif statement rather else statement code execution occur.
LIKE | SHARE | SUBSCRIBE