python - 哪种序列类型不支持 "extend slicing"?

标签 python slice

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'' orstride'' 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/

相关文章:

python - Django channel ; ECHO 示例不起作用

arrays - 无法使用 Golang 交换二维数组 slice 的元素

go - 如何在Golang中将变量参数传递给Sprintf

python - 如何按字母顺序组织以特定字母开头的字符串列表?

python - 在 python 中按值切片(未排序)数组

python - 使用计算值创建字典

python - 你如何刷新 Python 套接字?

python - 按数据框中的不同值划分列

python - 如果在 24 小时内重复,则保持值(value)

javascript - 使用变量属性值从javascript数组中删除对象