Python | 展示一个break语句示例
break is a keyword in python just like another programming language and it is used to break the execution of loop statement.
就像另一種編程語言一樣, break是python中的關鍵字,用于中斷loop語句的執行。
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.
在給定的示例中,循環從1到10運行,并且如果i的值為6,則使用break語句。因此,當i的值為6時,程序的執行將從循環中執行。
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
總結
以上是生活随笔為你收集整理的Python | 展示一个break语句示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 元气骑士宠物亲密度怎么增加
- 下一篇: kinect中psi是什么_PSI的完整