python3 for循环语句_【IT专家】python3 for 循环中的 else 语句

本文由我司收集整编,推荐下载,如有疑问,请与我司联系

python3 for

循环中的

else

语句

2017/04/21

10091

操作系统:

window7

x64

编程

IDE

Pycharm

2016.1.2

Python

版本:

3.6.1

编辑时间:

2017

4

21

版权所有:

OE,

转载请注明出处:

blog.csdn/csnd_ayo

英文原文

A break statement executed in the first suite terminates the loop without executing the

else clause

s suite. A continue statement executed in the first suite skips the rest of the

suite and continues with the next item, or with the else clause if there is no next item.

中文译文

break

关键字终止当前循环就不会执行当前的

else

语句,而使用

continue

关键字快速进入下一论循环,或者没有使用其他关键字,循环的正常结束

后,就会触发

else

语句。

触发

else

正常结束的循环

list = [1,2,3,4,5]for x in list: print(x)else: print(“else”)

使用

continue

关键字

list

=

[1,2,3,4,5]for

x

in

list:

continue

print(x)else:

print(“else”)

不触发

else

list

=

[1,2,3,4,5]for x in list: print(x) breakelse: print(“else”) for else

语句可以总结成以下话。

如果我依次做完了所有的事情

(for

正常结束

)

,我就去做其他事

(

执行

else)

,若做到

一半就停下来不做了(中途遇到

break

)

,我就不去做其他事了

(

不执行

else)

只有循环完所有次数,才会执行

else

break

可以阻止

else

语句块的执行。

tips:

感谢大家的阅读,本文由我司收集整编。仅供参阅!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值