欢迎来到天天文库
浏览记录
ID:82006558
大小:3.99 MB
页数:9页
时间:2022-07-06
《Python-图文课件5》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
第五章控制语句
1执行结构顺序结构做完一件事后紧接着做另一件事选择结构在某个条件成立的情况下做某件事循环结构反复做某件事,直到满足某个条件为止
2控制语句print('Here’stothecrazyones.')print('Themisfits.Therebels.Thetroublemakers.')print('Theroundpegsinthesquareholes.')print('Theoneswhoseethingsdifferently.')print('They’renotfondofrules.Andtheyhavenorespectforthestatusquo.')print('Youcanquotethem,disagreewiththem,glorifyorvilifythem.')print('Abouttheonlythingyoucan’tdoisignorethem.')print('')print('Becausetheychangethings.')print('Theypushthehumanraceforward.')print('Andwhilesomemayseethemasthecrazyones,weseegenius.')print('Becausethepeoplewhoarecrazyenoughtothinktheycanchangetheworld,aretheoneswhodo.')顺序结构代码按顺序执行
3控制语句if条件1:代码块1elif条件2:代码块2elif条件3:代码块3...elif条件n-1:代码块n-1else代码块n选择结构if语句
4控制语句if条件1:代码块1elif条件2:代码块2elif条件3:代码块3...elif条件n-1:代码块n-1else代码块n选择结构if语句代码块具有相同缩进的为一个代码块代码块内可以嵌套代码块
5控制语句while条件:代码块循环结构for语句while语句两种语句可以相互转化一般来说for语句要简洁可读一些for循环变量in可迭代对象:代码段
6Break,Continuei=0whilei<=50:i+=1ifi==2:continueelifi==4:breakprint(i)print('done')只能在循环中使用Break用于跳出当前循环Continue跳过当次循环13done
7Passa=0ifa>=10:passelse:print('aissmallerthan10')功能就是没有功能不造成任何影响很多时候只是为了维护语法完整性
8小结三种执行结构:顺序结构、选择结构、循环结构if语句用于选择结构while语句和for语句用于循环结构相同缩进的代码构成一个代码块
此文档下载收益归作者所有
举报原因
联系方式
详细说明
内容无法转码请点击此处