gpt4 book ai didi

python - Python切片中的 `a[start:stop, i]`是什么?

转载 作者:行者123 更新时间:2023-12-05 04:40:46 25 4
gpt4 key购买 nike

<分区>

built-in function slice 的 Python 文档是(强调我的):

class slice(stop)
class slice(start, stop[, step])

Return a slice object representing the set of indices specified by range(start, stop, step). The start and step arguments default to None. Slice objects have read-only data attributes start, stop and step which merely return the argument values (or their default). They have no other explicit functionality; however they are used by NumPy and other third party packages. Slice objects are also generated when extended indexing syntax is used. For example: a[start:stop:step] or a[start:stop, i]. See itertools.islice() for an alternate version that returns an iterator.

a[start:stop, i] 是什么意思?

我试过了(在 Python 3.6 中):

a = [1, 2, 3, 4, 5, 6]
a[1:3,1]

但是得到了:

TypeError: list indices must be integers or slices, not tuple

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com