Conditional Statements are features of a programming language, which perform different
computations or actions depending on whether the given condition evaluates to true or false.
Conditional statements in python are of 3 types
If statement
If else statement
If elif statement
Nested if else
1. If Statement : if Statement is used to run a statement conditionally i.e. if given
condition is true then only the statement given in if block will be executed.
if <condition>:
<if statement block >
For example consider the code given below
if (percentage > 33):
print (“Pass”)
Explaination : In the above code if value of percentage is above 33 then only
the message “Pass” will be printed.
2. If else Statement In the case of if else statement If given condition is true then the
statement given in if block will be executed otherwise(else) the statements written in
else block will be executed
if <condition>:
<if statement block >
else:
<else statement block>
For example consider the code given below
if (percentage > 33):
print (“Pass”)
else:
print(“Fail”)
Explaination : In the above code if value of percentage is above 33 then only
the message “Pass” will be printed otherwise it will print “Fail”