新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python中的for循環(huán)語句怎么寫
Python for循環(huán)可以遍歷任何序列的項(xiàng)目,如一個(gè)列表或者一個(gè)字符串。

10多年專注成都網(wǎng)站制作,成都定制網(wǎng)頁設(shè)計(jì),個(gè)人網(wǎng)站制作服務(wù),為大家分享網(wǎng)站制作知識(shí)、方案,網(wǎng)站設(shè)計(jì)流程、步驟,成功服務(wù)上千家企業(yè)。為您提供網(wǎng)站建設(shè),網(wǎng)站制作,網(wǎng)頁設(shè)計(jì)及定制高端網(wǎng)站建設(shè)服務(wù),專注于成都定制網(wǎng)頁設(shè)計(jì),高端網(wǎng)頁制作,對(duì)成都社區(qū)文化墻等多個(gè)方面,擁有豐富的營銷推廣經(jīng)驗(yàn)。
for循環(huán)的一般格式如下:
forin : else:
實(shí)例
>>>languages = ["C", "C++", "Perl", "Python"] >>> for x in languages: ... print (x) ... C C++ Perl Python >>>
以下 for 實(shí)例中使用了 break 語句,break 語句用于跳出當(dāng)前循環(huán)體:
sites = ["Baidu", "Google","Runoob","Taobao"]
for site in sites:
if site == "Runoob":
print("菜鳥教程!")
break
print("循環(huán)數(shù)據(jù) " + site)
else:
print("沒有循環(huán)數(shù)據(jù)!")
print("完成循環(huán)!")
執(zhí)行腳本后,在循環(huán)到 "Runoob"時(shí)會(huì)跳出循環(huán)體:
循環(huán)數(shù)據(jù) Baidu 循環(huán)數(shù)據(jù) Google 菜鳥教程! 完成循環(huán)!
網(wǎng)站題目:創(chuàng)新互聯(lián)Python教程:python中的for循環(huán)語句怎么寫
文章源于:http://m.fisionsoft.com.cn/article/cdddiij.html


咨詢
建站咨詢
