python循环语句
来源:互联网 发布:node留言板 编辑:程序博客网 时间:2024/06/05 09:34
python的循环代码
循环结构 for {var} in {list}
1.range(): 获取数字的范围
>>>range(7)
[0, 1, 2, 3, 4,5, 6]
>>>range(2,4)
[2, 3]
>>>range(1,8,3)
[1, 4, 7]
>>> fori in range(5):
print i
0
1
2
3
4
2.跳到下一项与跳出循环
continue: 跳到下一项
>>>for i in number:
ifi==1:
continue
else:
printi
2
3
4
break: 跳出循环
>>> fori in number:
if i==2:
break
else :
print i
1
@else语句允许为for循环添加另外一个代码块。只有当你不想跳出for循环时,才会运行这个代码块
>>> fori in number:
if i>4:
break
else:
print i
else:
print 'no number more than four'
1
2
3
4
no number morethan four
3. while循环
while number[i]<3:
i=i+1
>>> i
2
- Python中的循环语句
- Python中的循环语句
- python 循环语句
- Python循环语句
- Python for 循环语句
- Python While循环语句
- python循环语句
- python中的循环语句
- Python循环语句
- Python循环语句
- Python 循环语句
- Python循环语句
- Python循环语句
- python循环语句
- Python循环语句
- python的循环语句
- Python--While循环语句
- Python--for 循环语句
- 最小生成树 Kruskal 算法 和 Prim算法
- HDU 4971 最大权闭合图
- hdu2571 命运
- 学生接外包需注意的地方
- Rescue The Princess
- python循环语句
- 操作系统2015(四川大学软件学院)
- 横向listview
- 设计模式之建造者模式(Builder)
- C++笔记
- Windows下Python,setuptools,pip,virtualenv的安装
- LeetCode *** 199. Binary Tree Right Side View
- 对同一个表中不同的字段进行升序蒋序的操作sql中排序的误区
- 在action中使用Servlet的API松耦版