第4章 操作列表
# 4-1
pizzas = ["fruit pizza", "beef pizza", "seafood pizza"]
for pizza in pizzas:
print("I like " + pizza)
print("I really love pizza!")
# 4-10
a = list(range(1, 12))
print(a)
print("The first three items in the list are: ", a[:3])
print("Three items from the middle of the list are: ", a[(len(a)-1)//2-1:(len(a)-1)//2+2])
print("Three last three items in the list are: ", a[-3:])
# 4-11
pizzas = ["fruit pizza", "beef pizza", "seafood pizza"]
friend_pizzas = pizzas[:]
pizzas.append("mixed pizza")
friend_pizzas.append("grand pizza")
print("My favorite pizzas are:", pizzas)
print("My friend's favorite pizzas are:", friend_pizzas)