Multiple if VS if elif else

YU NA Joe·2022년 4월 5일
0

if if..(multiple if)

앞에 if문이 true이면은 다음 if로 넘어감

if elif else

앞에 if문이 true이면은 종료

i = 10

if (i == 10):
   
    #  First if statement
    if (i < 15):
        print("i is smaller than 15")
         
    # Nested - if statement
    # Will only be executed if statement above
    # it is true
    if (i < 12):
        print("i is smaller than 12 too")
    else:
        print("i is greater than 15")
        
# i is smaller than 15
# i is smaller than 12 too


x = 100 

if x > 10: 
    print("Yes, x > 10")

elif x > 20:
    print("Yes, x > 20")

else:
    print("not greater than 10")
# Yes, x > 10

0개의 댓글