|
楼主 |
发表于 2018-8-15 17:42:51
|
显示全部楼层
练习32.循环和列表[,]
the_count = [1,2,3,4,5]
fruits = ['apple','oranges','pears','apricots']
change = [1,'pennies',2,'dimes',3,'quarters']
#第一种列表for循环
for number in the_count:
print('this is count %d'%number)
#同上
for fruit in fruits:
print("a fruit of type: %s"%fruit)
#通过%r循环输出混合列表
for i in change:
print('I got %r'%i)
elements = []#空列表
for i in range(0,6):#0,1,2,3,4,5循环输出
print("adding %d to the list"%i)
elements.append(i)#添加到列表
for i in elements:#循环输出列表
print("element was: %d"%i)
|
|