序列協(xié)議?

int PySequence_Check(PyObject *o)?
Part of the Stable ABI.

Return 1 if the object provides the sequence protocol, and 0 otherwise. Note that it returns 1 for Python classes with a __getitem__() method, unless they are dict subclasses, since in general it is impossible to determine what type of keys the class supports. This function always succeeds.

Py_ssize_t PySequence_Size(PyObject *o)?
Py_ssize_t PySequence_Length(PyObject *o)?
Part of the Stable ABI.

成功時返回序列中*o*的對象數(shù),失敗時返回``-1``. 相當于Python的``len(o)``表達式.

PyObject *PySequence_Concat(PyObject *o1, PyObject *o2)?
Return value: New reference. Part of the Stable ABI.

成功時返回 o1o2 的拼接,失敗時返回 NULL。 這等價于 Python 表達式 o1 + o2。

PyObject *PySequence_Repeat(PyObject *o, Py_ssize_t count)?
Return value: New reference. Part of the Stable ABI.

返回序列對象 o 重復 count 次的結果,失敗時返回 NULL。 這等價于 Python 表達式 o * count

PyObject *PySequence_InPlaceConcat(PyObject *o1, PyObject *o2)?
Return value: New reference. Part of the Stable ABI.

成功時返回 o1o2 的拼接,失敗時返回 NULL。 在 o1 支持的情況下操作將 原地 完成。 這等價于 Python 表達式 o1 += o2

PyObject *PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count)?
Return value: New reference. Part of the Stable ABI.

Return the result of repeating sequence object返回序列對象 o 重復 count 次的結果,失敗時返回 NULL。 在 o 支持的情況下該操作會 原地 完成。 這等價于 Python 表達式 o *= count。

PyObject *PySequence_GetItem(PyObject *o, Py_ssize_t i)?
Return value: New reference. Part of the Stable ABI.

返回 o 中的第 i 號元素,失敗時返回 NULL。 這等價于 Python 表達式 o[i]。

PyObject *PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2)?
Return value: New reference. Part of the Stable ABI.

返回序列對象 oi1i2 的切片,失敗時返回 NULL。 這等價于 Python 表達式 o[i1:i2]

int PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v)?
Part of the Stable ABI.

將對象 v 賦值給 o 的第 i 號元素。 失敗時會引發(fā)異常并返回 -1;成功時返回 0。 這相當于 Python 語句 o[i] = v。 此函數(shù) 不會 改變對 v 的引用。

If v is NULL, the element is deleted, but this feature is deprecated in favour of using PySequence_DelItem().

int PySequence_DelItem(PyObject *o, Py_ssize_t i)?
Part of the Stable ABI.

刪除對象 o 的第 i 號元素。 失敗時返回 -1。 這相當于 Python 語句 del o[i]。

int PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2, PyObject *v)?
Part of the Stable ABI.

將序列對象 v 賦值給序列對象 o 的從 i1i2 切片。 這相當于 Python 語句 o[i1:i2] = v。

int PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2)?
Part of the Stable ABI.

刪除序列對象 o 的從 i1i2 的切片。 失敗時返回 -1。 這相當于 Python 語句 del o[i1:i2]

Py_ssize_t PySequence_Count(PyObject *o, PyObject *value)?
Part of the Stable ABI.

返回 valueo 中出現(xiàn)的次數(shù),即返回使得 o[key] == value 的鍵的數(shù)量。 失敗時返回 -1。 這相當于 Python 表達式 o.count(value)。

int PySequence_Contains(PyObject *o, PyObject *value)?
Part of the Stable ABI.

確定 o 是否包含 value。 如果 o 中的某一項等于 value,則返回 1,否則返回 0。 出錯時,返回 -1。 這相當于 Python 表達式 value in o。

Py_ssize_t PySequence_Index(PyObject *o, PyObject *value)?
Part of the Stable ABI.

返回第一個索引*i*,其中 o[i] == value.出錯時,返回 -1.相當于Python的``o.index(value)``表達式.

PyObject *PySequence_List(PyObject *o)?
Return value: New reference. Part of the Stable ABI.

返回一個列表對象,其內容與序列或可迭代對象 o 相同,失敗時返回 NULL。 返回的列表保證是一個新對象。 這等價于 Python 表達式 list(o)。

PyObject *PySequence_Tuple(PyObject *o)?
Return value: New reference. Part of the Stable ABI.

返回一個元組對象,其內容與序列或可迭代對象 o 相同,失敗時返回 NULL。 如果 o 為元組,則將返回一個新的引用,在其他情況下將使用適當?shù)膬热輼嬙煲粋€元組。 這等價于 Python 表達式 tuple(o)。

PyObject *PySequence_Fast(PyObject *o, const char *m)?
Return value: New reference. Part of the Stable ABI.

將序列或可迭代對象 o 作為其他 PySequence_Fast* 函數(shù)族可用的對象返回。 如果該對象不是序列或可迭代對象,則會引發(fā) TypeError 并將 m 作為消息文本。 失敗時返回 NULL。

PySequence_Fast* 函數(shù)之所以這樣命名,是因為它們會假定 o 是一個 PyTupleObjectPyListObject 并直接訪問 o 的數(shù)據(jù)字段。

作為 CPython 的實現(xiàn)細節(jié),如果 o 已經(jīng)是一個序列或列表,它將被直接返回。

Py_ssize_t PySequence_Fast_GET_SIZE(PyObject *o)?

Returns the length of o, assuming that o was returned by PySequence_Fast() and that o is not NULL. The size can also be retrieved by calling PySequence_Size() on o, but PySequence_Fast_GET_SIZE() is faster because it can assume o is a list or tuple.

PyObject *PySequence_Fast_GET_ITEM(PyObject *o, Py_ssize_t i)?
Return value: Borrowed reference.

oPySequence_Fast() 返回且 oNULL,并且 i d在索引范圍內的情況下返回 o 的第 i 號元素。

PyObject **PySequence_Fast_ITEMS(PyObject *o)?

返回 PyObject 指針的底層數(shù)組。 假設 oPySequence_Fast() 返回且 o 不為 NULL

請注意,如果列表調整大小,重新分配可能會重新定位items數(shù)組.因此,僅在序列無法更改的上下文中使用基礎數(shù)組指針.

PyObject *PySequence_ITEM(PyObject *o, Py_ssize_t i)?
Return value: New reference.

返回 o 的第 i 個元素或在失敗時返回 NULL。 此形式比 PySequence_GetItem() 理饌,但不會檢查 o 上的 PySequence_Check() 是否為真值,也不會對負序號進行調整。