???
Python ???? ????? ?? ??? ?????. ???? ?? ??? ?? ??? ?? ?? ??(True ?? False)? ?? ?????.
Python ????? ??? 0? ??? null? ?? ?? ?? True?? 0 ?? null? False?? ?????.
?? ???? ??? ????.
1. if ?? ?? ??
Python?? if ?? ?? ??? ??? ????.
if 判斷條件: 執(zhí)行語(yǔ)句…… else: 執(zhí)行語(yǔ)句……
?? ??? ??? , Python ???? ??? ???? ?? ??? ???? ????? ????? ???? ?? ??? ?? ?? ????: .
if ?? ?? ??? >(?? ?), <(?? ??), ==(??), >=(??? ??), <=(?? ??)?? ??? ? ????. ?? ??).
?:
# -*-coding:utf-8-*- results=59 if results>=60: print ('及格') else : print ('不及格')
?? ??? ??? ????.
不及格
??? ??? ??? 0? ?? ?, ?? ?? ?? ???, ?? ?? ?? ?? ?? True? ????, ??? ??? False? ?????. ??? ??? ?? ? ?? ????:
num = 6 if num : print('Hello Python')
2. if?? ?? ?? ?? ??
??? ??? ???? 2?? ?? ? ??, ??? 60? ??? ??? ?? ????. ?? ?? ?? ???? 90 ???? ????? ???? ??, 80~90 ???? ????? ???? ????
?? if?? ?? ?? ??? ???? ???.
?? ??? ???? ?????.
if 判斷條件1: 執(zhí)行語(yǔ)句1…… elif 判斷條件2: 執(zhí)行語(yǔ)句2…… elif 判斷條件3: 執(zhí)行語(yǔ)句3…… else: 執(zhí)行語(yǔ)句4……
?:
# -*-coding:utf-8-*- results = 89 if results > 90: print('優(yōu)秀') elif results > 80: print('良好') elif results > 60: print ('及格') else : print ('不及格')
?? ??:
良好
3. ???? ??? ?????
Python?? Java? ?? ??? ?? ???? ?? ?? ??? elif? ???? ??? ? ????. ??? ??? ?? ??? ??? ???? ?? ?? ??? ??? ? ????. (or) and (and)? ???? ? ?? ? ??? true? ???? ?? ??? ????? ?????.
# -*-coding:utf-8-*- java = 86 python = 68 if java > 80 and python > 80: print('優(yōu)秀') else : print('不優(yōu)秀') if ( java >= 80 and java < 90 ) or ( python >= 80 and python < 90): print('良好')
?? ??:
不優(yōu)秀 良好
??: ??? ?? ?? ?? ??? ???? ?? ??? ??? ? ????. ??, and ? or? ????? >?? ????. ;(?? ?), < ;(?? ??), ? ?? ? ? ?? ??? ?? ?? ??? ???? ?????.