집합 객체¶
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()).
- 
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¶ 이것은 파이썬
set형을 나타내는PyTypeObject의 인스턴스입니다.
- 
PyTypeObject 
PyFrozenSet_Type¶ 이것은 파이썬
frozenset형을 나타내는PyTypeObject의 인스턴스입니다.
다음 형 검사 매크로는 모든 파이썬 객체에 대한 포인터에서 작동합니다. 마찬가지로, 생성자 함수는 모든 이터러블 파이썬 객체에서 작동합니다.
- 
int 
PyAnySet_CheckExact(PyObject *p)¶ p가
set객체나frozenset객체이지만, 서브 형의 인스턴스는 아니면 참을 반환합니다. 이 함수는 항상 성공합니다.
- 
int 
PyFrozenSet_CheckExact(PyObject *p)¶ p가
frozenset객체이지만, 서브 형의 인스턴스는 아니면 참을 반환합니다. 이 함수는 항상 성공합니다.
- 
PyObject* 
PySet_New(PyObject *iterable)¶ - Return value: New reference.
iterable에 의해 반환된 객체를 포함하는 새로운
set을 반환합니다. iterable은 새로운 빈 집합을 만들기 위해NULL일 수 있습니다. 성공하면 새 집합을, 실패하면NULL을 반환합니다. iterable이 실제로 이터러블이 아니면TypeError를 발생시킵니다. 생성자는 집합을 복사할 때도 유용합니다 (c=set(s)). 
- 
PyObject* 
PyFrozenSet_New(PyObject *iterable)¶ - Return value: New reference.
iterable에 의해 반환된 객체를 포함한 새로운
frozenset을 반환합니다. iterable은 새로운 빈 frozenset을 만들기 위해NULL일 수 있습니다. 성공하면 새 집합을, 실패하면NULL을 반환합니다. iterable이 실제로 이터러블이 아니면TypeError를 발생시킵니다. 
set 이나 frozenset의 인스턴스 또는 그들의 서브 형의 인스턴스에 대해 다음 함수와 매크로를 사용할 수 있습니다.
- 
Py_ssize_t 
PySet_Size(PyObject *anyset)¶ set이나frozenset객체의 길이를 반환합니다.len(anyset)와 동등합니다. anyset이set,frozenset또는 서브 형의 인스턴스가 아니면PyExc_SystemError를 발생시킵니다.
- 
Py_ssize_t 
PySet_GET_SIZE(PyObject *anyset)¶ 에러 검사 없는
PySet_Size()의 매크로 형식.
- 
int 
PySet_Contains(PyObject *anyset, PyObject *key)¶ 발견되면
1을, 발견되지 않으면0을, 에러가 발생하면-1을 반환합니다. 파이썬__contains__()메서드와는 달리, 이 함수는 해시 불가능한 집합을 임시 frozenset으로 자동 변환하지 않습니다. key가 해시 불가능하면,TypeError를 발생시킵니다. anyset이set,frozenset또는 서브 형의 인스턴스가 아니면PyExc_SystemError를 발생시킵니다.
- 
int 
PySet_Add(PyObject *set, PyObject *key)¶ 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)¶ 발견되고 제거되면
1을 반환하고, 발견되지 않으면(아무런 일도 하지 않습니다)0을 반환하고, 에러가 발생하면-1을 반환합니다. 발견할 수 없는 키에 대해KeyError를 발생시키지 않습니다. key가 해시 불가능하면TypeError를 발생시킵니다. 파이썬discard()메서드와는 달리, 이 함수는 해시 불가능한 집합을 임시 frozenset으로 자동 변환하지 않습니다. set이set이나 그 서브 형의 인스턴스가 아니면PyExc_SystemError를 발생시킵니다.