首页 > 编程语言 > 详细

Python学习3——for语句

时间:2015-07-27 19:13:47      阅读:118      评论:0      收藏:0      [点我收藏+]
# python code by zzw
# time:2015-7-27
# for语句注意与其他语言的区别,感觉跟shell有点像

words=[‘dog‘,‘windows‘,‘Linux‘];
for w in words:
    print(‘the length of ‘,w,‘ is ‘,len(w));

运行结果

the length of  dog  is  3
the length of  windows  is  7
the length of  Linux  is  5


# python code by zzw
# time:2015-7-27
# for语句注意与其他语言的区别,感觉跟shell有点像

for i in range(10):
    print(i);

运行结果

0
1
2
3
4
5
6
7
8
9


# python code by zzw
# time:2015-7-27
# for语句注意与其他语言的区别,感觉跟shell有点像
# 这里表示从0开始,步长为3,并且最后一个值小于20

for i in range(0,20,3):
    print(i);

运行结果:

0
3
6
9
12
15
18


Python学习3——for语句

原文:http://my.oschina.net/zzw922cn/blog/484390

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!