热线电话:13121318867

登录
2019-04-11 阅读量: 726
Python如何遍历切片?

要遍历列表的部分元素,可在for 循环中使用切片。

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

处理数据时,可使用切片来进行批量处理;编写Web应用程序时,可使用切片来分页显示信息。

0.0000
3
关注作者
收藏
评论(0)

发表评论

暂无数据