pythonBreak语句的中断
python中Break语句的中断
1、说明
break用来跳出最近的for或者while循环。
要注意的是,for循环可以和else一起使用。
2、实例
循环中的else语句,会在for循环执行完毕,之后执行。如果我们使用break对for循环进行了中断,那么else语句将不会被执行。
In[64]:forninrange(2,10):
...:forxinrange(2,n):
...:ifn%x==0:
...:print(n,'equals',x,'*',n//x)
...:break
...:else:
...:print(n,'isaprimenumber')
...:
2isaprimenumber
3isaprimenumber
4equals2*2
5isaprimenumber
6equals2*3
7isaprimenumber
8equals2*4
9equals3*3
以上就是python中Break语句的中断,希望对大家有所帮助。更多Python学习推荐:请关注IT培训机构:千锋教育。

相关推荐HOT
更多>>
python怎么生成随机数
以下实例演示了python如何生成一个随机数:#生成0~9之间的随机数#导入random(随机数)模块importrandomprint(random.randint(0,9))执行以上代码...详情>>
2023-11-07 17:09:17
python如何删除空格
python中的字符串方法提供了如下常用的方法来删除空白:strip():删除字符串前后的空白。lstrip():删除字符串前面(左边)的空白。rstrip():删...详情>>
2023-11-07 14:57:44
python怎么调用实例方法
在Python的类体中定义的方法默认都是实例方法,也示范了通过对象来调用实例方法。但要提醒大家的是,Python的类在很大程度上可看做是一个独立的...详情>>
2023-11-07 14:17:57
python怎么创建mysql数据库连接
python数据库接口支持非常多的数据库,你可以选择适合你项目的数据库:GadFlymSQLMySQLPostgreSQLMicrosoftSQLServer2000InformixInterbase详情>>
2023-11-07 09:02:44