python切片器方法

slice indices must be integers or None or have an __index__ method

内置列表切片器方法

适用于列表、元祖和字符串。字典和集合本身无序,无索引,不能使用切片器

[start:end:step]#从位置start开始,步长step,一直取到end-1。即取头不取尾

[::-1] step为负数表逆序切

mlist=['orange','pineapple','blueberry','pear','peach']
mlist[1:4]                    #>>['pineapple', 'blueberry', 'pear']
'jimi and lucy'[1::5]         #>>'inc'
mtuple=(1,2,3)
mtuple[-1]                    #>>3

 

你可能感兴趣的:(python切片器方法)