当前位置:网站首页>学习总结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后面的代码在循环结束后不会执行
边栏推荐
- Requests the library deployment and common function
- 学习总结week3_2函数进阶
- uboot enable debug printing information
- Qt produces 18 frames of Cupid to express his love, is it your Cupid!!!
- In Opencv, imag=cv2.cvtColor(imag,cv2.COLOR_BGR2GRAY) error: error:!_src.empty() in function 'cv::cvtColor'
- LAB Semaphore Implementation Details
- day12函数进阶作业
- 2023 International Conference on Information and Communication Engineering (JCICE 2023)
- Transformation 和 Action 常用算子
- day7-列表作业(1)
猜你喜欢
Wise Force Deleter强制删除工具
Algorithms - ones and zeros (Kotlin)
The software design experiment four bridge model experiment
SQL(一) —— 增删改查
2022杭电多校第一场01
Lecture 4 Backpropagation Essays
Convert the paper official seal in the form of a photo into an electronic official seal (no need to download ps)
第5讲 使用pytorch实现线性回归
【过一下4】09-10_经典网络解析
[Let's pass 14] A day in the study room
随机推荐
ESP32 485 Illuminance
Requests the library deployment and common function
Matplotlib(二)—— 子图
range函数作用
Pycharm中使用pip安装第三方库安装失败:“Non-zero exit code (2)“的解决方法
2022 The 4th C.Easy Counting Problem (EGF+NTT)
数据库实验五 备份与恢复
SQL(二) —— join窗口函数视图
server disk array
human weakness
第四讲 back propagation 反向传播
小白一枚各位大牛轻虐虐
SQL(一) —— 增删改查
Structured Light 3D Reconstruction (2) Line Structured Light 3D Reconstruction
RDD和DataFrame和Dataset
【过一下12】整整一星期没记录
Xiaobai, you big bulls are lightly abused
span标签和p标签的区别
Using QR codes to solve fixed asset management challenges
Structured light 3D reconstruction (1) Striped structured light 3D reconstruction