#判斷
if 條件:
內容一
內容二
else: 如果的意思
內容三
內容四 示例如下:
name = raw_input ('請輸入用戶名:')
pwd = raw_input ('請輸入密碼:')
if name == "abc" and pwd == "123qwe":
print ('登錄成功')
else:
print ('登錄失敗')
基本條件語句:多個條件判斷示例:
inp = raw_input(">>>>")
if inp == "1":
print ("111")
elif inp == "2":
print ("222")
elif inp == "3":
print ("333")
else:
print (".....")
總結:if else
if 條件:
代碼塊
else:
代碼塊
2 if 條件:
代碼塊
elif 條件:
代碼塊
else:
代碼塊
3 條件
True False
1 > 2 n1 > n2 n1 == n2
name == "abc" or name == "acc"
name != "abc"
name == "abc" and pwd == "123"