python中循环结构分有,python常见循环结构有哪些

050af9349946e8c6eb904aab9e788d2f.png

1、for…in…

该格式在python中是最为常见的一种格式,使用极为广泛。格式:for 参数 in 循环体:

pass

在上面的格式中,有很多内容可以作为循环体,比如元组、列表、字符串等等。只要能穿越循环,就可以作为循环体存在。

其中参数主要用来存储每个循环体发送的单个元素,从而实现循环功能。在实践中,它经常与if判断语句结合使用。#input

str_01 = '时间都去哪了!!!'

for i in str_01:

print(i)

#output

2、while

while循环和for…in…循环的不同之处在于,while要先将循环变量初始化或者直接使用while True 这种死循环形式。格式:i = 0

while i >=10:

pass

i +=1#input

while True:

print('hello world!!!__hello python!!!')

#output

hello world!!!__hello python!!!

hello world!!!__hello python!!!

hello world!!!__hello python!!!

hello world!!!__hello python!!!

hello world!!!__hello python!!!

hello world!!!__hello python!!!

hello world!!!__hello python!!!

hello world!!!__hello python!!!

hello world!!!__hello python!!!

.

.

.

.

.

.

以上就是python中2种常见循环结构,希望能对大家有所帮助。更多Python学习指路:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值