-4
我有了下面的列表Python列表对象,洗牌Python的list
a=[1, 2, 3, 0, 4].
我想用下面的代码来将它洗:
from random import shuffle
shuffle(a)
但是,什么是下面代码的含义:
a[::-1]
[4, 0, 3, 2, 1] # output
我知道python的slice索引。但我从来没有见过上面的表格。所以,我不明白为什么这是有效的?
感谢。
那不是洗牌 - 这是逆转。 – miradulo
请参阅[扩展切片]的文档(https://docs.python.org/2/whatsnew/2.3.html#extended-slices)表示法。 –
这是我的错。我已经拥有了,谢谢大家。 – vincent