4-1 比萨
pizzas = ['fruit pizza', 'bacon pizza', 'seafood pizza']
for pizza in pizzas:
print(pizza)
for pizza in pizzas:
print("I like " + pizza)
print("I really love pizza!")
4-7 3的倍数
values = list(range(3, 31, 3))
print(values)
4-9 立方解析
values = [value**3 for value in range(1, 11)]
print(values)
4-10 切片
values = [value**3 for value in range(1, 11)]
print(values)
print("The first three items in the list are:")
print(values[:3])
print("Three items from the middle of the list are:")
print(values[3:6])
print("The last three items in the list are:")
print(values[-3:])
4-13 自助餐
foods = ('apple', 'pizza', 'chips', 'chicken', 'hamburger')
for food in foods:
print(food)
#food[0] = 'banana'
foods = ('banana', 'cola', 'chips', 'chicken', 'hamburger')
for food in foods:
print(food)