首页 > 其他 > 详细

4.4使用列表的一部分

时间:2018-10-25 13:17:20      阅读:189      评论:0      收藏:0      [点我收藏+]

  4.4.1切片

players = [charles, martina, michael, florence, eli]
print(players[0:3])
[charles, martina, michael]

4.4.2 遍历切片

players = [charles, martina, michael, florence, eli]
print("Here are the first three players on my team:")
for player in players[:3]:
    print(player.title())
Charles
Martina
Michael

4.4.3 复制列表

my_foods = ["pizza", falafel, carrot cake]
friends_foods = my_foods[:]
print("My favorite foods are:")
print(my_foods)
print("\nMy friend‘s favorite foods are:")
print(friends_foods)
技术分享图片
My favorite foods are:
[pizza, falafel, carrot cake]

My friends favorite foods are:
[pizza, falafel, carrot cake]
View Code

 

4.4使用列表的一部分

原文:https://www.cnblogs.com/yuxinjack/p/9848902.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!