집합 객체¶
This section details the public API for set and frozenset
objects. Any functionality not listed below is best accessed using either
the abstract object protocol (including PyObject_CallMethod(),
PyObject_RichCompareBool(), PyObject_Hash(),
PyObject_Repr(), PyObject_IsTrue(), PyObject_Print(), and
PyObject_GetIter()) or the abstract number protocol (including
PyNumber_And(), PyNumber_Subtract(), PyNumber_Or(),
PyNumber_Xor(), PyNumber_InPlaceAnd(),
PyNumber_InPlaceSubtract(), PyNumber_InPlaceOr(), and
PyNumber_InPlaceXor()).
-
type PySetObject¶
This subtype of
PyObjectis used to hold the internal data for bothsetandfrozensetobjects. It is like aPyDictObjectin that it is a fixed size for small sets (much like tuple storage) and will point to a separate, variable sized block of memory for medium and large sized sets (much like list storage). None of the fields of this structure should be considered public and all are subject to change. All access should be done through the documented API rather than by manipulating the values in the structure.
-
PyTypeObject PySet_Type¶
- Part of the Stable ABI.
이것은 파이썬
set형을 나타내는PyTypeObject의 인스턴스입니다.
-
PyTypeObject PyFrozenSet_Type¶
- Part of the Stable ABI.
이것은 파이썬
frozenset형을 나타내는PyTypeObject의 인스턴스입니다.
다음 형 검사 매크로는 모든 파이썬 객체에 대한 포인터에서 작동합니다. 마찬가지로, 생성자 함수는 모든 이터러블 파이썬 객체에서 작동합니다.
-
int PySet_CheckExact(PyObject *p)¶
Return true if p is a
setobject but not an instance of a subtype. This function always succeeds.Added in version 3.10.
-
int PyAnySet_CheckExact(PyObject *p)¶
p가
set객체나frozenset객체이지만, 서브 형의 인스턴스는 아니면 참을 반환합니다. 이 함수는 항상 성공합니다.
-
int PyFrozenSet_CheckExact(PyObject *p)¶
p가
frozenset객체이지만, 서브 형의 인스턴스는 아니면 참을 반환합니다. 이 함수는 항상 성공합니다.
-
PyObject *PySet_New(PyObject *iterable)¶
- Return value: New reference. Part of the Stable ABI.
iterable에 의해 반환된 객체를 포함하는 새로운
set을 반환합니다. iterable은 새로운 빈 집합을 만들기 위해NULL일 수 있습니다. 성공하면 새 집합을, 실패하면NULL을 반환합니다. iterable이 실제로 이터러블이 아니면TypeError를 발생시킵니다. 생성자는 집합을 복사할 때도 유용합니다 (c=set(s)).
-
PyObject *PyFrozenSet_New(PyObject *iterable)¶
- Return value: New reference. Part of the Stable ABI.
iterable에 의해 반환된 객체를 포함한 새로운
frozenset을 반환합니다. iterable은 새로운 빈 frozenset을 만들기 위해NULL일 수 있습니다. 성공하면 새 집합을, 실패하면NULL을 반환합니다. iterable이 실제로 이터러블이 아니면TypeError를 발생시킵니다.
set 이나 frozenset의 인스턴스 또는 그들의 서브 형의 인스턴스에 대해 다음 함수와 매크로를 사용할 수 있습니다.
-
Py_ssize_t PySet_Size(PyObject *anyset)¶
- Part of the Stable ABI.
Return the length of a
setorfrozensetobject. Equivalent tolen(anyset). Raises aSystemErrorif anyset is not aset,frozenset, or an instance of a subtype.
-
Py_ssize_t PySet_GET_SIZE(PyObject *anyset)¶
에러 검사 없는
PySet_Size()의 매크로 형식.
-
int PySet_Contains(PyObject *anyset, PyObject *key)¶
- Part of the Stable ABI.
Return
1if found,0if not found, and-1if an error is encountered. Unlike the Python__contains__()method, this function does not automatically convert unhashable sets into temporary frozensets. Raise aTypeErrorif the key is unhashable. RaiseSystemErrorif anyset is not aset,frozenset, or an instance of a subtype.
-
int PySet_Add(PyObject *set, PyObject *key)¶
- Part of the Stable ABI.
Add key to a
setinstance. Also works withfrozensetinstances (likePyTuple_SetItem()it can be used to fill in the values of brand new frozensets before they are exposed to other code). Return0on success or-1on failure. Raise aTypeErrorif the key is unhashable. Raise aMemoryErrorif there is no room to grow. Raise aSystemErrorif set is not an instance ofsetor its subtype.
다음 함수는 set 이나 그것의 서브 형의 인스턴스에는 사용할 수 있지만, frozenset 이나 그 서브 형의 인스턴스에는 사용할 수 없습니다.
-
int PySet_Discard(PyObject *set, PyObject *key)¶
- Part of the Stable ABI.
Return
1if found and removed,0if not found (no action taken), and-1if an error is encountered. Does not raiseKeyErrorfor missing keys. Raise aTypeErrorif the key is unhashable. Unlike the Pythondiscard()method, this function does not automatically convert unhashable sets into temporary frozensets. RaiseSystemErrorif set is not an instance ofsetor its subtype.
-
PyObject *PySet_Pop(PyObject *set)¶
- Return value: New reference. Part of the Stable ABI.
set에 들어있는 임의의 객체에 대한 새 참조를 반환하고, set에서 객체를 제거합니다. 실패하면
NULL을 반환합니다. 집합이 비어 있으면,KeyError를 발생시킵니다. set이set이나 그 서브 형의 인스턴스가 아니면SystemError를 발생시킵니다.
-
int PySet_Clear(PyObject *set)¶
- Part of the Stable ABI.
Empty an existing set of all elements. Return
0on success. Return-1and raiseSystemErrorif set is not an instance ofsetor its subtype.