当前位置:网站首页>学习总结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后面的代码在循环结束后不会执行
边栏推荐
猜你喜欢

OFDM Lecture 16 5 -Discrete Convolution, ISI and ICI on DMT/OFDM Systems

Algorithms - ones and zeros (Kotlin)
![coppercam入门手册[6]](/img/d3/a7d44aa19acfb18c5a8cacdc8176e9.png)
coppercam入门手册[6]
![[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)

Structured light 3D reconstruction (1) Striped structured light 3D reconstruction

DOM及其应用

The difference between span tag and p

第5讲 使用pytorch实现线性回归

"Recursion" recursion concept and typical examples

Using pip to install third-party libraries in Pycharm fails to install: "Non-zero exit code (2)" solution
随机推荐
第二讲 Linear Model 线性模型
entry point injection
jvm three heap and stack
[Study Notes Dish Dog Learning C] Classic Written Exam Questions of Dynamic Memory Management
Flex layout frog game clearance strategy
Lecture 2 Linear Model Linear Model
redis复制机制
1068找到更多的硬币
number_gets the specified number of decimals
day7-列表作业(1)
human weakness
day12函数进阶作业
【过一下10】sklearn使用记录
Flutter learning - the beginning
Requests the library deployment and common function
Algorithms - ones and zeros (Kotlin)
数字_获取指定位数的小数
Multi-threaded query results, add List collection
What are the characteristics of the interface of the physical layer?What does each contain?
Lecture 4 Backpropagation Essays