【每天1分钟】PYTHON基础之条件与循环(循环控制)
2019-07-22 23:02
429 查看
版权声明:署名,允许他人基于本文进行创作,且必须基于与原先许可协议相同的许可协议分发本文 (Creative Commons)
【每天1分钟】PYTHON基础之条件与循环(循环控制)
- break
break:跳出循环,不再执行
流程图
代码示例
>>> for digit in range(10): if digit == 5: break print('the number is: {digit}'.format(digit = digit)) the number is: 0 the number is: 1 the number is: 2 the number is: 3 the number is: 4 >>> >>> L = list(range(10)) >>> while len(L) >= 1: tmp = L.pop() if tmp == 3: break print(tmp) 9 8 7 6 5 4 >>>
- continue
continue 跳过当前循环的剩余语句,然后继续进行下一轮循环。
流程图
代码示例
>>> for digit in range(10): if digit == 5: continue print('the number is: {digit}'.format(digit = digit)) the number is: 0 the number is: 1 the number is: 2 the number is: 3 the number is: 4 the number is: 6 the number is: 7 the number is: 8 the number is: 9 >>> >>> L = list(range(10)) >>> while len(L) >= 1: tmp = L.pop() if tmp == 3: continue print(tmp) 9 8 7 6 5 4 2 1 0 >>>
- pass
pass 不做任何事情,一般用做占位语句。
代码示例
>>> for digit in range(10): if digit == 5: pass print('the number is: {digit}'.format(digit = digit)) the number is: 0 the number is: 1 the number is: 2 the number is: 3 the number is: 4 the number is: 5 the number is: 6 the number is: 7 the number is: 8 the number is: 9 >>> >>> L = list(range(10)) >>> while len(L) >= 1: tmp = L.pop() if tmp == 3: pass print(tmp) 9 8 7 6 5 4 3 2 1 0 >>>
相关文章推荐
- 【每天1分钟】PYTHON基础之条件与循环(列表解析)
- 【每天1分钟】PYTHON基础之条件与循环(迭代器)
- 【每天1分钟】PYTHON基础之条件与循环(else 子句)
- 【每天1分钟】PYTHON基础之条件与循环(几个返回迭代器的函数)
- Python基础作业_第06章_条件控制和循环语句
- python基础知识点数据类型转换、条件控制语句、循环语句、字符串、元组、字典、逻辑运算符
- Python3基础之条件与循环控制实例解析
- Python基础语法学习--条件控制与循环语句
- python基础之条件控制与循环
- Python3基础之条件与循环控制实例解析
- python流程控制-条件与循环-python3笔记
- Python基础:条件判断与循环的两个要点
- Python新手学习基础之循环结构——循环控制break continue pass
- Python基础编程(五)条件、循环和其他语句
- Python基础入门之条件判断和循环二
- Python3条件与循环控制
- JS基础学习第四天:条件控制语句、循环语句、函数模块、事件等通用代码块2
- python基础学习之——条件判断和循环
- python学习:条件控制语句,循环语句,数字
- Python3.5基础——变量、数据结构、条件和循环语句、break与continue语句