리스트 객체

type PyListObject

PyObject의 서브 형은 파이썬 리스트 객체를 나타냅니다.

PyTypeObject PyList_Type
Part of the 안정 ABI.

PyTypeObject 인스턴스는 파이썬 리스트 형을 나타냅니다. 이것은 파이썬 계층의 list와 같은 객체입니다.

int PyList_Check(PyObject *p)
Thread safety: Atomic.

p가 리스트 객체나 리스트 형의 서브 형 인스턴스면 참을 반환합니다. 이 함수는 항상 성공합니다.

int PyList_CheckExact(PyObject *p)
Thread safety: Atomic.

p가 리스트 객체이지만 리스트 형의 서브 형의 인스턴스가 아니면 참을 반환합니다. 이 함수는 항상 성공합니다.

PyObject *PyList_New(Py_ssize_t len)
반환값: 새 참조. Part of the 안정 ABI. Thread safety: Atomic.

성공하면 길이 len 인 새 리스트를, 실패하면 NULL을 반환합니다.

참고

len이 0보다 크면, 반환된 리스트 객체의 항목은 NULL로 설정됩니다. 따라서 모든 항목을 PyList_SetItem()이나 PyList_SET_ITEM()으로 실제 객체로 설정하기 전에 PySequence_SetItem()와 같은 추상 API 함수를 사용하거나 파이썬 코드에 객체를 노출할 수 없습니다. 다음 API는 리스트가 완전히 초기화되기 전의 안전한 API 입니다: PyList_SetItem()PyList_SET_ITEM().

Py_ssize_t PyList_Size(PyObject *list)
Part of the 안정 ABI. Thread safety: Atomic.

list에서 리스트 객체의 길이를 반환합니다; 이는 리스트 객체에 대한 len(list)와 동등합니다.

Py_ssize_t PyList_GET_SIZE(PyObject *list)
Thread safety: Atomic.

PyList_Size()와 유사하지만, 에러 검사가 없습니다.

PyObject *PyList_GetItemRef(PyObject *list, Py_ssize_t index)
반환값: 새 참조. Part of the 안정 ABI 버전 3.13 이후로. Thread safety: Atomic.

list가 가리키는 리스트에서 index 위치의 객체를 반환합니다. 위치는 음수가 아니어야 합니다; 리스트의 끝에서부터의 인덱싱은 지원되지 않습니다. index가 범위를 벗어나면 (<0 or >=len(list)), NULL을 반환하고 IndexError 예외를 설정합니다.

Added in version 3.13.

PyObject *PyList_GetItem(PyObject *list, Py_ssize_t index)
반환값: 빌린 참조. Part of the 안정 ABI. Thread safety: Safe to call from multiple threads with external synchronization only.

Like PyList_GetItemRef(), but returns a borrowed reference instead of a strong reference.

참고

In the free-threaded build, the returned borrowed reference may become invalid if another thread modifies the list concurrently. Prefer PyList_GetItemRef(), which returns a strong reference.

PyObject *PyList_GET_ITEM(PyObject *list, Py_ssize_t i)
반환값: 빌린 참조. Thread safety: Safe to call from multiple threads with external synchronization only.

PyList_GetItem()와 유사하지만, 에러 검사가 없습니다.

참고

In the free-threaded build, the returned borrowed reference may become invalid if another thread modifies the list concurrently. Prefer PyList_GetItemRef(), which returns a strong reference.

int PyList_SetItem(PyObject *list, Py_ssize_t index, PyObject *item)
Part of the 안정 ABI. Thread safety: Atomic.

리스트의 인덱스 index에 있는 항목을 item으로 설정합니다. 성공하면 0을 반환합니다. index가 범위를 벗어나면, -1을 반환하고 IndexError 예외를 설정합니다.

참고

이 함수는 item에 대한 참조를 “훔치고” 영향을 받는 위치의 리스트에 이미 있는 항목에 대한 참조를 버립니다.

void PyList_SET_ITEM(PyObject *list, Py_ssize_t i, PyObject *o)
Thread safety: Safe to call from multiple threads with external synchronization only.

에러 검사 없는 PyList_SetItem()의 매크로 형식. 일반적으로 이전 내용이 없는 새 리스트를 채우는 데 사용됩니다.

Bounds checking is performed as an assertion if Python is built in debug mode or with assertions.

참고

이 매크로는 item에 대한 참조를 “훔치고”, PyList_SetItem()과는 달리 대체되는 항목에 대한 참조를 버리지 않습니다; listi 위치에 있는 참조는 누수를 일으킵니다.

참고

In the free-threaded build, this macro has no internal synchronization. It is normally only used to fill in new lists where no other thread has a reference to the list. If the list may be shared, use PyList_SetItem() instead, which uses a per-object lock.

int PyList_Insert(PyObject *list, Py_ssize_t index, PyObject *item)
Part of the 안정 ABI. Thread safety: Safe for concurrent use on the same object.

항목 item을 리스트 list의 인덱스 index 앞에 삽입합니다. 성공하면 0을 반환합니다; 실패하면 -1을 반환하고 예외를 설정합니다. list.insert(index, item)에 해당합니다.

int PyList_Append(PyObject *list, PyObject *item)
Part of the 안정 ABI. Thread safety: Atomic.

리스트 list의 끝에 객체 item을 추가합니다. 성공하면 0을 반환합니다; 실패하면 -1을 반환하고 예외를 설정합니다. list.append(item)에 해당합니다.

PyObject *PyList_GetSlice(PyObject *list, Py_ssize_t low, Py_ssize_t high)
반환값: 새 참조. Part of the 안정 ABI. Thread safety: Atomic.

list에서 lowhigh 사이에있는 객체들을 포함하는 리스트를 반환합니다. 실패하면 NULL을 반환하고 예외를 설정합니다. list[low:high]에 해당합니다. 리스트 끝에서부터의 인덱싱은 지원되지 않습니다.

int PyList_SetSlice(PyObject *list, Py_ssize_t low, Py_ssize_t high, PyObject *itemlist)
Part of the 안정 ABI. Thread safety: Safe for concurrent use on the same object.

lowhigh 사이의 list슬라이스를 itemlist의 내용으로 설정합니다. list[low:high] = itemlist에 해당합니다. itemlistNULL 일 수 있는데, 빈 리스트의 대입을 나타냅니다 (슬라이스 삭제). 성공하면 0을, 실패하면 -1을 반환합니다. 리스트 끝에서부터의 인덱싱은 지원되지 않습니다.

참고

In the free-threaded build, when itemlist is a list, both list and itemlist are locked for the duration of the operation. For other iterables (or NULL), only list is locked.

int PyList_Extend(PyObject *list, PyObject *iterable)
Thread safety: Safe for concurrent use on the same object.

Extend list with the contents of iterable. This is the same as PyList_SetSlice(list, PY_SSIZE_T_MAX, PY_SSIZE_T_MAX, iterable) and analogous to list.extend(iterable) or list += iterable.

Raise an exception and return -1 if list is not a list object. Return 0 on success.

Added in version 3.13.

참고

In the free-threaded build, when iterable is a list, set, dict, or dict view, both list and iterable (or its underlying dict) are locked for the duration of the operation. For other iterables, only list is locked; iterable may be concurrently modified by another thread.

int PyList_Clear(PyObject *list)
Thread safety: Atomic.

Remove all items from list. This is the same as PyList_SetSlice(list, 0, PY_SSIZE_T_MAX, NULL) and analogous to list.clear() or del list[:].

Raise an exception and return -1 if list is not a list object. Return 0 on success.

Added in version 3.13.

int PyList_Sort(PyObject *list)
Part of the 안정 ABI. Thread safety: Safe for concurrent use on the same object.

list 항목을 제자리에서 정렬합니다. 성공하면 0을, 실패하면 -1을 반환합니다. 이것은 list.sort()와 동등합니다.

참고

In the free-threaded build, element comparison via __lt__() can execute arbitrary Python code, during which the per-object lock may be temporarily released. For built-in types (str, int, float), the lock is not released during comparison.

int PyList_Reverse(PyObject *list)
Part of the 안정 ABI. Thread safety: Safe for concurrent use on the same object.

list의 항목을 제자리에서 뒤집습니다. 성공하면 0을, 실패하면 -1을 반환합니다. 이것은 list.reverse()와 동등합니다.

PyObject *PyList_AsTuple(PyObject *list)
반환값: 새 참조. Part of the 안정 ABI. Thread safety: Atomic.

list의 내용을 포함하는 새 튜플 객체를 반환합니다; tuple(list)와 동등합니다.