当前位置:网站首页>学习总结day5
学习总结day5
2022-08-05 05:13:00 【非鱼丶丶】
python循环语句关键字
一:continue和break
continue和break都是循环体关键字(只出现在循环中)
1)continue - 结束一次循环(结束当次循环)
在执行循环体的时候如果遇到continue,那么这次循环结束,直接进入下次循环
2)break - 结束整个循环
for x in range(5):
if x % 2 == 0:
continue
print(x)
for m in range(5):
if m > 3:
break
print(m)
2.while使用套路
例:如果num是偶数就打印偶数,是奇数就打印奇数,如果能被4整除,打印4的倍数
while True:
每次循环需要做的事情(重复执行代码)
if 循环结束条件:
break
# 猜数字游戏,随机产生一个数(0-100),让用户猜测
from random import randint
num = randint(1, 100)
count = 0
while count < 7:
a = int(input('输入数字'))
count += 1
if a == num:
print('正确')
break
else:
if a > num:
print('大了')
else:
print('小了')
print('cai')
二:循环else
完整的for循环:
for 变量 in 序列:
循环体
else:
代码段
完整的while循环:
while 条件语句:
循环体
else:
代码段
1)else不会影响循环
2)如果else对应的循环是自然结束,else后面的代码段会执行;
如果其循环是因为遇到break而结束的,那么else后面的代码在循环结束后不会执行
边栏推荐
猜你喜欢

Algorithms - ones and zeros (Kotlin)

vscode+pytorch use experience record (personal record + irregular update)

2022 Hangzhou Electric Multi-School 1st Session 01

CAP+BASE

shell函数

Matplotlib(二)—— 子图

DOM and its applications

结构光三维重建(二)线结构光三维重建
![[Student Graduation Project] Design and Implementation of the Website Based on the Web Student Information Management System (13 pages)](/img/86/9c9a2541f2b7089ae47e9832fffdb3.png)
[Student Graduation Project] Design and Implementation of the Website Based on the Web Student Information Management System (13 pages)

第5讲 使用pytorch实现线性回归
随机推荐
Understanding and use of C# on set() and get() methods
第四讲 反向传播随笔
Error creating bean with name 'configDataContextRefresher' defined in class path resource
Flutter真机运行及模拟器运行
Convert the paper official seal in the form of a photo into an electronic official seal (no need to download ps)
ES6 生成器
Flex layout frog game clearance strategy
What are the characteristics of the interface of the physical layer?What does each contain?
NodeJs接收上传文件并自定义保存路径
【记一下1】2022年6月29日 哥和弟 双重痛苦
jvm 三 之堆与栈
将照片形式的纸质公章转化为电子公章(不需要下载ps)
Multi-threaded query results, add List collection
Community Sharing|Tencent Overseas Games builds game security operation capabilities based on JumpServer
小白一枚各位大牛轻虐虐
RDD和DataFrame和Dataset
redis复制机制
【cesium】Load and locate 3D Tileset
Xiaobai, you big bulls are lightly abused
入口点注入