在你开始使用 for 循环之前,你需要在某个位置存放循环的结果。最好的方法是使用
列表 (list),顾名思义,它就是一个按顺序存放东西的容器
#!/bin/usr/python
the_count = [1,2,3,4,5,6]
fruits = ['bananle','apricots','pears','oranges','apples']
changes = [1,'banbale',2,'orange',3,'apples']
for number in the_count:
print "this is count %d" % number
for fruit in fruits:
print "this is fuit %s" % fruit
for change in changes:
print "this is change %r" % change
elements=[]
for a in range(1,6):
print "this is %d" %a
elements.append(a)
for b in elements:
print "this is elements %d" %b
执行脚本 输出结果