Conditional Statement

0

Conditional Statement

  • Conditional statement are used to execute a block of statement on the basis of some condition.

Python supports the usual logical conditions from mathematics:-

  • Equals: a == b 
  • Not Equals: a != b 
  • Less than: a < b 
  • Less than or equal to: a <= b 
  • Greater than: a > b 
  • Greater than or equal to: a >= b

1. If Statement

Example :-

             a = 33
             b = 200
             if  b > a:
                    print("b is greater than a") 
     

2. Elif Statement

  • The elif  keyword is python way of saying "if the previous conditions were not true, then try this condition".

 Example :-
  
       a = 45
       b = 45
       if  b > a:
              print("b is greater than a")
       elif a==b:
              print("a and b are equal")

3. Else Statement

The else keyword catches anything which isn't caught by the preceding conditions.

Example :-
     
         a =  56
         b = 45
         if  b > a:
                print("b is greater than a")
         elif  a==b:
                print("a and b are equal")
         else:
                print("a is greater than b")


        

Tags

Post a Comment

0Comments
Post a Comment (0)