for循环

# -*- coding: utf-8 -*-
# @Author: yt
# @Date:   2018-05-19 20:12:11
# @Last Modified by:   yt
# @Last Modified time: 2018-05-19 20:18:54

the_count = [1,2,3,4,5]
fruits = ['apples','oranges','pears','apricots']
change = [1,'pennies',2,'dimes',3,'quarters']

#通过list循环
for number in the_count:
    print "This is count %d"%number

for fruit in fruits:
    print "A fruit of type:%s"%fruit


for i in change:
    print "I got %r"%i

elements = []

for i in range(0,6):
    print "Adding %d to the list."%i
    elements.append(i)

for i in elements:
    print "Element was: %d"%i

运行结果如下:
for循环_第1张图片
图1

你可能感兴趣的:(for循环)