新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:Python中的continue是什么
Python continue 語句跳出本次循環(huán),而break跳出整個循環(huán)。

continue語句用來告訴Python跳過當前循環(huán)的剩余語句,然后繼續(xù)進行下一輪循環(huán)。
continue語句用在while和for循環(huán)中。
Python 語言 continue 語句語法格式如下:
continue
實例
#!/usr/bin/python3
for letter in 'Runoob': # 第一個實例
if letter == 'o': # 字母為 o 時跳過輸出
continue
print ('當前字母 :', letter)
var = 10 # 第二個實例
while var > 0:
var = var -1
if var == 5: # 變量為 5 時跳過輸出
continue
print ('當前變量值 :', var)
print ("Good bye!")執(zhí)行以上腳本輸出結(jié)果為:
當前字母 : R 當前字母 : u 當前字母 : n 當前字母 : b 當前變量值 : 9 當前變量值 : 8 當前變量值 : 7 當前變量值 : 6 當前變量值 : 4 當前變量值 : 3 當前變量值 : 2 當前變量值 : 1 當前變量值 : 0 Good bye!
網(wǎng)站標題:創(chuàng)新互聯(lián)Python教程:Python中的continue是什么
鏈接地址:http://www.5511xx.com/article/coosohj.html


咨詢
建站咨詢
