Python 引用 http://docs.python.org/2/reference/datamodel.html 说:
Some sequences also support “extended slicing” with a third “step” parameter: a[i:j:k] selects all items of a with index x where x = i + n*k, n >= 0 and i <= x < j.
那么哪些序列类型不支持“扩展切片”呢?
最佳答案
如今,任何用户定义的序列都不想/不需要支持它。所有当前的 Python 内置函数都可以这样做;在过去 - 情况并非如此......请参阅 http://www.python.org/dev/peps/pep-0283/你会看到...
Extended slice notation for all built-in sequences. The patch by Michael Hudson is now all checked in.
这涉及到:
http://docs.python.org/release/2.3.4/whatsnew/section-slices.html
Ever since Python 1.4, the slicing syntax has supported an optional third
step'' or
stride'' argument. For example, these are all legal Python syntax: L[1:10:2], L[:-1:1], L[::-1]. This was added to Python at the request of the developers of Numerical Python, which uses the third argument extensively. However, Python's built-in list, tuple, and string sequence types have never supported this feature, raising a TypeError if you tried it. Michael Hudson contributed a patch to fix this shortcoming.
关于python - 哪种序列类型不支持 "extend slicing"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18912505/