Python | 展示一个break语句示例
break is a keyword in python just like another programming language and it is used to break the execution of loop statement.
就像另一種編程語(yǔ)言一樣, break是python中的關(guān)鍵字,用于中斷l(xiāng)oop語(yǔ)句的執(zhí)行。
In the given example, loop is running from 1 to 10 and we are using the break statement if the value of i is 6. Thus when the value of i will be 6, program's execution will come out from the loop.
在給定的示例中,循環(huán)從1到10運(yùn)行,并且如果i的值為6,則使用break語(yǔ)句。因此,當(dāng)i的值為6時(shí),程序的執(zhí)行將從循環(huán)中執(zhí)行。
Example 1:
范例1:
for i in range(1,11):if(i==6):breakprint(i)Output
輸出量
1 2 3 4 5Example 2: In this example, we are printing character by character of the value/string “Hello world” and terminating (using break), if the character is space.
示例2:在此示例中,如果字符為空格,則按字符/值/字符串“ Hello world”打印字符并終止(使用break)。
for ch in "Hello world":if ch == " ":breakprint(ch)Output
輸出量
H e l l o翻譯自: https://www.includehelp.com/python/break-statement-example.aspx
總結(jié)
以上是生活随笔為你收集整理的Python | 展示一个break语句示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 元气骑士宠物亲密度怎么增加
- 下一篇: go zap去除程序名称_适用于Zip,