Multiple if VS if elif else


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