日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python循环中的else_python 循环中else的简单示例

發(fā)布時間:2023/12/10 python 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python循环中的else_python 循环中else的简单示例 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

導讀熱詞對python這個高級語言感興趣的小伙伴,下面一起跟隨編程之家 jb51.cc的小編兩巴掌來看看吧!

眾多語言中都有if else這對條件選擇組合,但是在python中還有更多else使用的地方,比如說循環(huán)for,或者while都可以和else組合。

下面簡單介紹一下for-else while-else組合

循環(huán)組合中的else執(zhí)行的情況下是循環(huán)正常結(jié)束(即不是使用break退出)。如下列代碼:

# @param 你所不知道的python 循環(huán)中的else

# @author 編程之家 jb51.cc|www.www.jb51.cc

numbers = [1,2,3,4,5]

for n in numbers:

if (n > 5):

print('the value is %d '%(n))

break

else:

print('the for loop does not end with break')

i = 0

while(numbers[i] < 5):

print('the index %d value is %d'%(i,numbers[i]))

if (numbers[i] < 0) :

break

i = i + 1

else:

print('the loop does not end with break')

numbers = [1,5]

for n in numbers:

if (n > 5):

print('the value is %d '%(n))

break

else:

print('the for loop does not end with break')

i = 0

while(numbers[i] < 5):

print('the index %d value is %d'%(i,numbers[i]))

if (numbers[i] < 0) :

break

i = i + 1

else:

print('the loop does not end with break')

# End www.jb51.cc

執(zhí)行結(jié)果如下:

# @param 你所不知道的python 循環(huán)中的else

# @author 編程之家 jb51.cc|www.www.jb51.cc

C:\Python27>python.exe for_else.py

the for loop does not end with break

the index 0 value is 1

the index 1 value is 2

the index 2 value is 3

the index 3 value is 4

the loop does not end with break

# End www.jb51.cc

相關(guān)文章

總結(jié)

如果覺得編程之家網(wǎng)站內(nèi)容還不錯,歡迎將編程之家網(wǎng)站推薦給程序員好友。

本圖文內(nèi)容來源于網(wǎng)友網(wǎng)絡(luò)收集整理提供,作為學習參考使用,版權(quán)屬于原作者。

如您喜歡交流學習經(jīng)驗,點擊鏈接加入交流1群:1065694478(已滿)交流2群:163560250

總結(jié)

以上是生活随笔為你收集整理的python循环中的else_python 循环中else的简单示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。