3.Python條件判斷(if else elif)


#判斷
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"


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM