Python多分支if語句的使用
注意:if語句代碼是從上往下執(zhí)行的,當(dāng)執(zhí)行到滿足條件的語句時(shí),代碼會停止往下執(zhí)行
注意:if語句后面要加上冒號
score = int (input('score:'))if score > 90: print('A')elif score > 80: print('B')elif score > 70: print('C')elif score > 60: print('D')else score < 60: print('加油吧孩紙')
補(bǔ)充知識:python之if語句以及條件測試( and 、or、in、not in)
1.and 、or、in、not in
’’’條件測試’’’#單個(gè)條件測試age0 = 22print(age0>=22) # True#多個(gè)條件測試 andage0 = 22age1 = 18print(age0>=21 and age1>=21) #False#多個(gè)條件測試 orprint(age0>=21 or arg0>=21) #True #in和not in(檢查特定值是否在列表中)fruits = [’apple’,’banana’,’orange’]print(’apple’ in fruits) #Trueprint(’apple’ not in fruits) #False
2.if語句
’’’簡單的if語句(僅包含一個(gè)測試和一個(gè)操作)’’’height = 1.7if height>=1.3: print(’高’)
’’’if-else’’’height = 1.8if height<=1.4: print(’免票’)else: print(’全票’)#最后輸出全票
’’’if-elif’’’height = 1.5if height>=1.4: print(’嘿嘿’)elif height>=1.3: print(’呵呵’)#最后輸出嘿嘿
’’’if-elif-else’’’height = 1.8if height<=1.4: print(’免票’)elif height>1.4 and height<=1.7: print(’半票’)else: print(’全票’)#最后輸出全票
以上這篇Python多分支if語句的使用就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. python實(shí)現(xiàn)讀取類別頻數(shù)數(shù)據(jù)畫水平條形圖案例2. python中PyQuery庫用法分享3. python操作數(shù)據(jù)庫獲取結(jié)果之fetchone和fetchall的區(qū)別說明4. Ajax實(shí)現(xiàn)頁面無刷新留言效果5. 阿里前端開發(fā)中的規(guī)范要求6. JSP+Servlet實(shí)現(xiàn)文件上傳到服務(wù)器功能7. 關(guān)于HTML5的img標(biāo)簽8. php5.6不能擴(kuò)展redis.so的解決方法9. CSS3實(shí)現(xiàn)動態(tài)翻牌效果 仿百度貼吧3D翻牌一次動畫特效10. PHP獲取時(shí)間戳等相關(guān)函數(shù)匯總
