概述
#! /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
最后
以上就是昏睡钢笔为你收集整理的python循环函数怎么改变变量_python函数与循环、变量的综合使用的全部内容,希望文章能够帮你解决python循环函数怎么改变变量_python函数与循环、变量的综合使用所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复