判斷:
1、單分支判斷語句
if 條件:
內容1
內容2
else:
內容3
內容4
實例:
1 if 1 == 1: 2 print("yes") 3 else: 4 print("no")
2、多分支判斷語句
if 條件:
內容1
內容2
elif 條件
內容3
elif 條件
內容4
else:
內容5
實例:
1 inp = input(">>>") 2 if inp == "1": 3 print("111") 4 elif inp == "2": 5 print("222") 6 elif inp == "3" 7 print("333") 8 else: 9 print(".....")
3、帶有與and、或or的 if 判斷語句
實例:
1 name = input("username") 2 pwd = input("password") 3 if name == "alex" and pwd == "123": 4 print("yes") 5 elif name == "alex1" or pwd == "123" 6 print("yes") 7 else: 8 print("no")