> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/python/cpython/llms.txt
> Use this file to discover all available pages before exploring further.

# Set Objects

> Working with Python set and frozenset types

## Overview

Sets are unordered collections of unique hashable objects.

## Creating Sets

```c theme={null}
PyObject* PySet_New(PyObject *iterable)
PyObject* PyFrozenSet_New(PyObject *iterable)
```

**Example:**

```c theme={null}
PyObject *set = PySet_New(NULL);  // Empty set
return set;
```

## Set Operations

```c theme={null}
int PySet_Add(PyObject *set, PyObject *key)
int PySet_Discard(PyObject *set, PyObject *key)
int PySet_Contains(PyObject *anyset, PyObject *key)
Py_ssize_t PySet_Size(PyObject *anyset)
```

**Example:**

```c theme={null}
PyObject *item = PyLong_FromLong(42);
PySet_Add(set, item);
Py_DECREF(item);

if (PySet_Contains(set, item)) {
    printf("Set contains 42\n");
}
```

## Set Methods

```c theme={null}
PyObject* PySet_Pop(PyObject *set)
void PySet_Clear(PyObject *set)
```

## See Also

* [Dictionary Objects](/c-api/dict)
* [Object Protocol](/c-api/object)
