python list 切片实验

list[start:stop:step]

>>> a_list=['hito','bb','cc','dd','ee','ff']
>>> a_list[::-1]                          #'-'号逆序,stop 默认为list最后一位,start 默认为list的第一位
['ff', 'ee', 'dd', 'cc', 'bb', 'hito']
>>> a_list[4::-1]        
['ee', 'dd', 'cc', 'bb', 'hito']
>>> a_list[4::1]          #正数为自左往右,start为4,stop默认为最后一位
['ee', 'ff']
>>> a_list[::2]          #step定义为2
['hito', 'cc', 'ee']
>>> a_list[::]           #a_list
['hito', 'bb', 'cc', 'dd', 'ee', 'ff']

原文地址:https://www.cnblogs.com/hito/p/4508043.html