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语句示例的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 元气骑士宠物亲密度怎么增加
- 下一篇: go zap去除程序名称_适用于Zip,