Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1074993
  • 博文数量: 120
  • 博客积分: 887
  • 博客等级: 准尉
  • 技术积分: 1883
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-05 21:10
个人简介

RHCE,CCNA,熟悉shell脚本

文章分类

全部博文(120)

文章存档

2015年(16)

2014年(20)

2013年(48)

2012年(20)

2011年(16)

分类: Python/Ruby

2013-11-24 23:13:58

#! /usr/bin/python
i = 0
o = 7
p = 2
numbers = []

def w(startnum,endnum):
        while startnum < endnum:
                print "At the top is %d" % startnum
                numbers.append(startnum)
                startnum += p    #使用变量p
                print "Numbers now: ",numbers
                print "At the bottom i is %d" % startnum
w(i,o)        #函数w引用实参i,o
print "The numbers: "
for num in numbers:
        print num
'''-----------------------将代码改为用for-loop----------------'''
#! /usr/bin/python
i = 0
o = 6

numbers = []
for s in range(i,o):
        print "print i: %d " % s
        numbers.append(s)
        print "Numbers now: ", numbers

print "The numbers: "
for num in numbers:
    print num
'''----------range()在for-loop中的用法-----------'''
i = 1
o = 6
numbers = range(i,o)

for j in numbers:
    print "numbers was: %d" % j
阅读(680) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~