列表对象

type PyListObject

此子类型的 PyObject represents a Python list object.

PyTypeObject PyList_Type
属于 稳定 ABI (应用程序二进制接口) .

此实例的 PyTypeObject represents the Python list type. This is the same object as list 在 Python 层。

int PyList_Check ( PyObject * p )

返回 True 若 p is a list object or an instance of a subtype of the list type. This function always succeeds.

int PyList_CheckExact ( PyObject * p )

返回 True 若 p is a list object, but not an instance of a subtype of the list type. This function always succeeds.

PyObject * PyList_New ( Py_ssize_t len )
返回值:新引用。 属于 稳定 ABI (应用程序二进制接口) .

Return a new list of length len 当成功时,或 NULL 当故障时。

注意

len is greater than zero, the returned list object’s items are set to NULL . Thus you cannot use abstract API functions such as PySequence_SetItem() or expose the object to Python code before setting all items to a real object with PyList_SetItem() or PyList_SET_ITEM() . The following APIs are safe APIs before the list is fully initialized: PyList_SetItem() and PyList_SET_ITEM() .

Py_ssize_t PyList_Size ( PyObject * list )
属于 稳定 ABI (应用程序二进制接口) .

Return the length of the list object in list ; this is equivalent to len(list) on a list object.

Py_ssize_t PyList_GET_SIZE ( PyObject * list )

类似于 PyList_Size() , but without error checking.

PyObject * PyList_GetItemRef ( PyObject * list , Py_ssize_t index )
返回值:新引用。 属于 稳定 ABI (应用程序二进制接口) since version 3.13.

Return the object at position index in the list pointed to by list . The position must be non-negative; indexing from the end of the list is not supported. If index is out of bounds ( <0 or >=len(list) ), return NULL and set an IndexError 异常。

3.13 版添加。