tutorial5 foreach



In [1]:
fruits = ['apples','oranges','pears','bananas']
for fruit in fruits:
    print fruit + ' for sale'


apples for sale
oranges for sale
pears for sale
bananas for sale

In [4]:
fruitPrices = {'apples':2.00, 'oranges': 1.50, 'pears': 1.75}
for fruit, price in fruitPrices.items():
    print '%s cost %f a pound' % (fruit, price)


pears cost 1.750000 a pound
apples cost 2.000000 a pound
oranges cost 1.500000 a pound

In [ ]: