1. 遍历整个列表
magicians = ['alice', 'david', 'carolina']
for magician in magicians:
print(magician)
2. 使用range()创建数字列表
squares = []
for value in range(1,11):
squares.append(value**2)
print(squares)
3. 使用列表的一部分(切片)
players = ['charles', 'martina', 'michael', 'florence', 'eli']
print(players[0:3])
4. 遍历切片
players = ['charles', 'martina', 'michael', 'florence', 'eli']
print("Here are the first three players on my team:")
for player in players[:3]:
print(player.title())
5. 复制列表
my_foods = ['pizza', 'falafel', 'carrot cake']
friend_foods = my_foods[:] # my_foods 和 friend_foods 指两个不同的列表
friend_foods = my_foods # my_foods 和 friend_foods 指同一个列表