码迷,mamicode.com
首页 > 编程语言 > 详细

【python】理解循环:for,while

时间:2017-04-28 13:42:07      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:style   默认   blog   while   不包含   pytho   总结   odi   含义   

先看下for结构:

#!/usr/bin/python
# -*- Coding:UTF-8 -*-

for i in range(1):
    print i

输出:

0

 

输入和输出:

#!/usr/bin/python
# -*- Coding:UTF-8 -*-

for i in range(1, 10):
    print i

#输出: 1 2 3 4 5 6 7 8 9

输入和输出:

#!/usr/bin/python
# -*- Coding:UTF-8 -*-

for i in range(1, 10, 2):
    print i,

#输出:1 3 5 7 9

总结:

range([start=0], stop, [step=1])函数的含义:

1,从start开始,到stop结束,步长是step;

2,如果range只有一个参数,那么从0开始到stop-1结束;

3,step默认步长是1,可以重新写入为2或者更多;

4,起点包含start,终点不包含stop,到stop-1截止(start <= i < stop)

【python】理解循环:for,while

标签:style   默认   blog   while   不包含   pytho   总结   odi   含义   

原文地址:http://www.cnblogs.com/helww/p/6780921.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!