In [2]: list=range(627开发者_高级运维)
In [3]: list[::150]
Out[3]: [0, 150, 300, 450, 600]
the above code is right,but if i use the bellow code,caution:the l means long type, the return result is not like above,what's the hell?
In [4]: list=[1323l,123123l,4444l,12312312l]
In [5]: list=[1323l,123123l,4444l,12312312l]
In [6]: list[::2]
Out[6]: [1323L, 4444L]
The step denotes the multiples of indices that are included in the slice, not of the actual values contained in the array. In your second example:
list[0] = 1323L
list[1] = 123123L
list[2] = 4444L
list[3] = 12312312L
Since you're using the default argument for the start of the slice, it will start at the first element (list[0]
), and it will get every 2nd element after that, so it will also get list[2]
. It does not look at what those elements are, only at their indices.
精彩评论