""" 列表切片(获取想要位置长度的列表(子集))"""players = ['charles', 'martina', 'michael', 'florence', 'eli'] print(players[0:3]) print(players[1:]) print(players[:2]) """ 遍历切片 """for player in players[:3]: print(
print(players[0:3])
print(players[1:])
print(players[:2])
""" 遍历切片
"""for player in players[:3]:
print(player.title())
""" 复制列表
"""copy_players = players[:]
print(copy_players)
copy_players = players[2:4]
print(copy_players)
""" 练习题
"""foods_list = ['pizza', 'falafel', 'carrot cake', 'cannoli']
print('当前食物清单为:')
for foods in foods_list:
print('['+foods+']', end = ' || ')
print('\n')
friend_foods = foods_list[0:3]
print('我的朋友爱吃的食物清单为:'+str(friend_foods))
foods_list.append('hamburger')
print('当前食物清单为:'+str(foods_list))
print('我的朋友爱吃的食物清单为:'+str(friend_foods))