리스트 객체¶
-
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예외를 설정합니다.참고
This function “steals” a reference to item, even on error. On success, it discards a reference to an item already in the list at the affected position (unless it was
NULL).
-
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.참고
This macro “steals” a reference to item, and, unlike
PyList_SetItem(), does not discard a reference to any item that is being replaced; any reference in list at position i will be leaked.참고
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에서 low 와 high 사이에있는 객체들을 포함하는 리스트를 반환합니다. 실패하면
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.
low와 high 사이의 list슬라이스를 itemlist의 내용으로 설정합니다.
list[low:high] = itemlist에 해당합니다. itemlist는NULL일 수 있는데, 빈 리스트의 대입을 나타냅니다 (슬라이스 삭제). 성공하면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 (orNULL), 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 tolist.extend(iterable)orlist += iterable.Raise an exception and return
-1if list is not alistobject. 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 tolist.clear()ordel list[:].Raise an exception and return
-1if list is not alistobject. 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()와 동등합니다.
PyListBuilder¶
The PyListBuilder API can be used to create a Python list
object.
On the free-threaded build, it’s more efficient than the PyList C API to
create a list, because it can avoid the critical section on the
created list.
Added in version 3.16.0a2 (unreleased).
-
type PyListBuilder¶
- Part of the 안정 ABI (as an opaque struct) 버전 3.16 이후로.
A list builder object.
The API is not thread safe. To share a builder with multiple threads, external synchronization is needed.
The instance must be destroyed by
PyListBuilder_Finish()on success, orPyListBuilder_Discard()on error.
-
PyListBuilder *PyListBuilder_Create(Py_ssize_t size)¶
- Part of the 안정 ABI 버전 3.16 이후로.
Create a
PyListBuilderand preallocate size items.On error, set an exception and return
NULL.size must be positive or zero.
-
PyObject *PyListBuilder_Finish(PyListBuilder *builder)¶
- Part of the 안정 ABI 버전 3.16 이후로.
Finish a
PyListBuildercreated byPyListBuilder_Create().On success, return a Python
listobject. On error, set an exception and returnNULL.The builder instance is invalid after the call in any case. No API can be called on the builder after
PyListBuilder_Finish().
-
void PyListBuilder_Discard(PyListBuilder *builder)¶
- Part of the 안정 ABI 버전 3.16 이후로.
Discard a
PyListBuildercreated byPyListBuilder_Create().Do nothing if builder is
NULL.The builder instance is invalid after the call. No API can be called on the builder after
PyListBuilder_Discard().
-
int PyListBuilder_Append(PyListBuilder *builder, PyObject *item)¶
- Part of the 안정 ABI 버전 3.16 이후로.
Append an item to the list builder. Similar to
PyList_Append().On success, return
0. On error, set an exception, leave the builder unchanged, and return-1.
-
int PyListBuilder_AppendSteal(PyListBuilder *builder, PyObject *item)¶
- Part of the 안정 ABI 버전 3.16 이후로.
Same as
PyListBuilder_Append(), except this function steals the reference to item.
-
int PyListBuilder_Extend(PyListBuilder *builder, PyObject *iterable)¶
- Part of the 안정 ABI 버전 3.16 이후로.
Extend the list builder with the contents of iterable. Similar to
PyList_Extend().On success, return
0. On error, set an exception, leave the builder unchanged, and return-1.If consuming iterable raises an exception, the builder is restored to its previous state, that is, items added by a failed call are discarded. However, note that iterable is not reverted: items consumed from an iterator are not added back.
-
int PyListBuilder_ExtendArray(PyListBuilder *builder, PyObject *const *items, Py_ssize_t nitem)¶
- Part of the 안정 ABI 버전 3.16 이후로.
Extend the list builder with the contents of items: copy references from items to the list builder.
On success, return
0. On error, set an exception, leave the builder unchanged, and return-1.nitem must not be negative.
On failure, the builder is restored to its previous state. That is, items added by a failed call are discarded from the builder.
-
int PyListBuilder_ExtendArraySteal(PyListBuilder *builder, PyObject *const *items, Py_ssize_t nitem)¶
- Part of the 안정 ABI 버전 3.16 이후로.
Same as
PyListBuilder_ExtendArray(), but steal references instead of copying them.The caller must hold a strong reference to each item in item. Both on success and on error, these references are transferred to the builder; the caller must not use them after the call. (To clarify: on error, the references are “lost”.)