首頁 > 後端開發 > Python教學 > Python 中的循環控制語句:break、continue、pass

Python 中的循環控制語句:break、continue、pass

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
發布: 2024-08-23 06:01:36
原創
1325 人瀏覽過

Loop Control statements in Python : break, continue, pass

在Python中,我們有3種循環控制語句:break、continue和pass。

休息

當條件滿足時,循環中斷並跳出迴圈。

for i in range(10):
    print(i)
    if i == 5:
        break

# It will print : 0 to 5 and once the condition satisfies, 
# then the loop breaks.
登入後複製

繼續

當條件滿足時,它會被跳過並進入循環中的下一個迭代。

for i in range(10):
    if i == 5:
        continue
    print(i)

# It will print : 0 to 9 except 5.

登入後複製
for i in range(10):
    if i != 5 :
        continue
    print(i)

# It will print just 5.
登入後複製

經過

它什麼也沒做。它充當佔位符。

for i in range(10):
    if i == 5:
        pass
    print(i)

# It will not do anything, even if the condition satisfies
登入後複製

以上是Python 中的循環控制語句:break、continue、pass的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板