剛開始python的小強---if判斷語句


判斷:

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")

 


免責聲明!

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



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