top of page

If-Else Statement in Python

Updated: Apr 19, 2023




If statement is used to check whether a condition is either true or not.


If a condition is false, then the elif statement is used to check for another condition.


The else statement is used when none of the conditions match.


Any type of comparison operators can be used like <, <=, >, etc.


The and keyword is used to match all the conditions.


The or keyword is used to match only one of the conditions.




a = [1,2,3,4]

if 20 in a:
    print(2)
elif 30 in a:
    print(30)
elif 40 in a:
    print(40)
else:
    print("No")
 
b = 20
c = 30 
    
if b > c:
    print(b)
elif b == c:
    print("equal")
else:
    print(c)
    
    
if b > c and b%2 == 0:
    print(b)
elif b == c or c == 1:
    print(c)
elif b not in a:
    print(a)
    
    
if b < c:
    pass
    

The link to the Github repository is here .



bottom of page