PYTHON 学习笔记 007

if statement

#1.if 判断式,判断布林值,如为True,则执行IF里的程式码,False则会执行if以外的程式码handsome = Trueif handsome:    print("你是帅哥!!!!")#2.if,else: 布林值为False,执行else (否则....)handsome = Falseif handsome:    print("QUAPO!!!!!")else:    print("QAQ")

http://img2.58codes.com/2024/20156136foDA7xiTp0.jpg

#3.if,elif,else: 布林值符合哪一个程度就执行哪个程式码(TURE)age=70if age>=65:    print("敬老")elif age>=12:    print("成人")elif age>=6:    print("小孩佔床")elif age<=2:    print("婴儿")else:    print("小孩不佔床")age=22if age>=65:    print("敬老")elif age>=12:    print("成人")elif age>=6:    print("小孩佔床")elif age<=2:    print("婴儿")else:    print("小孩不佔床")age=11if age>=65:    print("敬老")elif age>=12:    print("成人")elif age>=6:    print("小孩佔床")elif age<=2:    print("婴儿")else:    print("小孩不佔床")age=4if age>=65:    print("敬老")elif age>=12:    print("成人")elif age>=6:    print("小孩佔床")elif age<=2:    print("婴儿")else:    print("小孩不佔床")age=2if age>=65:    print("敬老")elif age>=12:    print("成人")elif age>=6:    print("小孩佔床")elif age<=2:    print("婴儿")else:    print("小孩不佔床")

http://img2.58codes.com/2024/20156136wjkvvKrOHN.jpg

#4.双重条件判断:if and ,两者皆须True执行IF内程式,否则ELSEhight=185thin=Trueif hight>=175 and thin:    print("又高又瘦")else:    print("普通")hight=165thin=Trueif hight>=175 and thin:    print("又高又瘦")else:    print("普通")hight=185thin=Falseif hight>=175 and thin:    print("又高又瘦")else:    print("普通")hight=170thin=Falseif hight>=175 and thin:    print("又高又瘦")else:    print("普通")

http://img2.58codes.com/2024/20156136mRITtk8FbK.jpg

#5.or 满足其一条件为TRUE,否则为ELSEfinalscore=32attend=Trueif finalscore>=60 or attend:    print("PASSED!!!")else:    print("You cannot pass!!!!!")finalscore=80attend=Falseif finalscore>=60 or attend:    print("PASSED!!!")else:    print("You cannot pass!!!!!")finalscore=59attend=Falseif finalscore>=60 or attend:    print("PASSED!!!")else:    print("You CANNOT PASS!!!!!")

http://img2.58codes.com/2024/20156136fKHFBwdEkh.jpg

#6.or not :false 除非两边皆为FALSE,否则为TRUE。#如果邦交国低于10国,或不友善,则为被孤立国家;否则为受欢迎国家。#此例为邦交国12国,友善,人气国度。 # false or not true = false or false =false (执行ELSE)lands=12friendly=Trueif lands<10 or not(friendly):    print("Isolated!")else:    print("Amiable!!")#此例为邦交国9国,友善,被孤立国。 # true or not true = true or false = true (执行IF)lands=9friendly=Trueif lands<10 or not(friendly):    print("Isolated!")else:    print("Amiable!!")#此例为邦交国12国,不友善,被孤立国。 # false or not false = false or true = true (执行IF)lands=12friendly=Falseif lands<10 or not(friendly):    print("Isolated!")else:    print("Amiable!!")

http://img2.58codes.com/2024/20156136Mn42o0yLiV.jpg

#7. != 不等于# true or not true = true or false = true (执行IF)#得到不等于150下的摇尾或不喜欢,代表不怎么受欢迎,否则令人惊艳。#得到100下的摇尾或不喜欢,代表不怎么受欢迎。waves=100likes=Trueif waves!=150 or not(likes):    print("not as popular as")else:    print("amazing")# not true or not true = false or false = false (执行ELSE)#得到不等于150下的摇尾或不喜欢,代表不怎么受欢迎,否则令人惊艳。#得到150下的摇尾,满足其一条件,令人惊豔。waves=150likes=Trueif waves!=150 or not(likes):    print("not as popular as")else:    print("amazing")

http://img2.58codes.com/2024/20156136ia9PRc7rwo.jpg


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章