标签:索引 ati 特性 range code from 开始 ons 截取
dlist = doList[0:3]
表示,从索引0开始取,直到索引3为止,但不包括索引3。即索引0,1,2,正好是3个元素dolist = [1,3,5,7,9,11] dlist = dolist[0:3] # 与range()函数一致含左不含右 nlist = dolist[:3] # 当开始值为0时,可以不写,效果与dlist一致 print(dlist) print(nlist)
slist = dolist[-2:]
表示,从倒数第2个索引开始,取到索引为0为止,不包扩索引0# 倒序切片 slist = dolist[-2:] rlist = dolist[-4:-2] print(slist) print(rlist)
jlist = dolist[::2]
# 每2个索引切片标签:索引 ati 特性 range code from 开始 ons 截取
原文地址:https://www.cnblogs.com/thloveyl/p/11397398.html