Conditional Statements
Conditional statements are used to making a decision based on conditions. Conditional statements are evaluated to true or false. These statements are also known as decision-making statements.
Classifications
There are various types of conditional statements.
- If statement
- If-else statement
- Nested-if statement
- Elif statement
If Statement
If statement is used for decision-making operations. In if statement if the condition is true then the statement written in the if clause will be executed, otherwise not.
Syntax
if (condition):
statement
Program
a = 10
b = 20
if (a<=b):
print(" a is less then b.")
Output:
a is less then b.
If-Else Statement
If-else statements are used for decision-making operations. In if-else statements, if condition is true then the statement written in the if clause will be executed, otherwise statement written in the else clause will be executed.
Syntax
if (condition):
statement
else:
statement
Program
a = 30
b = 20
if (a<b):
print("a is less then b.")
else:
print("a is greater then b.")
Output:
a is greater then b.




0 Comments