码迷,mamicode.com
首页 > 编程语言 > 详细

python中列表分片

时间:2020-12-23 12:31:49      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:type   col   16px   pre   nbsp   span   元素   rgb   pytho   

 

>>> test1 = ["aa","bb","cc","dd","ee","ff"]
>>> type(test1)
<class ‘list‘>
>>> len(test1)
6
>>> test1[0:3]   ##  不包含索引为3的元素
[‘aa‘, ‘bb‘, ‘cc‘]
>>> test1[2:4]   ## 不包含索引为4的元素
[‘cc‘, ‘dd‘]>>> test1[:4]
[‘aa‘, ‘bb‘, ‘cc‘, ‘dd‘]
>>> test1[2:]
[‘cc‘, ‘dd‘, ‘ee‘, ‘ff‘]
>>> test1[:]  ## 完整列表
[‘aa‘, ‘bb‘, ‘cc‘, ‘dd‘, ‘ee‘, ‘ff‘]
>>> test1[-3:]   ## 取后三个元素
[‘dd‘, ‘ee‘, ‘ff‘]

 

python中列表分片

标签:type   col   16px   pre   nbsp   span   元素   rgb   pytho   

原文地址:https://www.cnblogs.com/liujiaxin2018/p/14157017.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!