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

# Python frozenset

A `frozenset` is a built-in Python data type representing an immutable, unordered collection of unique, hashable elements. It serves as the immutable counterpart to Python's standard `set` type, meaning its internal state and element composition cannot be modified after instantiation. Because a `frozenset` is immutable and Python strictly requires all of its elements to be hashable, the `frozenset` itself is hashable. This characteristic allows a `frozenset` to be used as a dictionary key or as an element within another `set`—operations that are impossible with a standard mutable `set`.

## Instantiation

Because it is immutable, a `frozenset` must be populated at the time of creation using the `frozenset()` constructor. The constructor accepts a single optional iterable argument. Attempting to instantiate a `frozenset` with unhashable elements (such as lists or dictionaries) immediately raises a `TypeError`.

```python theme={"dark"}

# Empty frozenset
empty_fs = frozenset()


# Instantiation from an iterable (list)

# Duplicates are automatically discarded
fs_from_list = frozenset([1, 2, 3, 2, 1])  

# Result: frozenset({1, 2, 3})


# Instantiation from a string
fs_from_string = frozenset("hello")        

# Result: frozenset({'h', 'e', 'l', 'o'})


# Utilizing hashability: frozenset as a dict key and set element
fs_key = frozenset(['a', 'b'])
my_dict = {fs_key: "value"}
my_set = {fs_key, frozenset([1, 2])}
```

## Technical Characteristics

* **Immutability:** Once created, elements cannot be added, removed, or altered.
* **Hashability:** Unlike a standard `set`, a `frozenset` implements a `__hash__()` method. Because Python enforces that all elements within any set type must be hashable, a `frozenset` is guaranteed to evaluate to a constant hash value.
* **Unordered:** Elements do not maintain insertion order. Consequently, a `frozenset` does not support indexing, slicing, or other sequence-like behaviors.
* **Uniqueness:** It strictly enforces element uniqueness. Duplicate values passed during instantiation are ignored.

## Supported Operations

A `frozenset` supports all non-mutating mathematical set operations. These operations evaluate the elements and return a new `frozenset` or a boolean value, leaving the original objects unchanged.

```python theme={"dark"}
fs_a = frozenset([1, 2, 3])
fs_b = frozenset([3, 4, 5])


# Union (Returns elements in either set)
fs_a | fs_b                  # frozenset({1, 2, 3, 4, 5})
fs_a.union(fs_b)


# Intersection (Returns elements common to both sets)
fs_a & fs_b                  # frozenset({3})
fs_a.intersection(fs_b)


# Difference (Returns elements in fs_a not in fs_b)
fs_a - fs_b                  # frozenset({1, 2})
fs_a.difference(fs_b)


# Symmetric Difference (Returns elements in either set, but not both)
fs_a ^ fs_b                  # frozenset({1, 2, 4, 5})
fs_a.symmetric_difference(fs_b)


# Relational Checks (Returns boolean)
fs_a <= fs_b                 # False (issubset)
fs_a >= frozenset([1, 2])    # True  (issuperset)
fs_a.isdisjoint(fs_b)        # False (True if no common elements)
```

## Unsupported Operations

Because a `frozenset` is immutable, it lacks the in-place mutating methods found on a standard `set`. Attempting to invoke any of the following methods will raise an `AttributeError`:

```python theme={"dark"}
fs = frozenset([1, 2, 3])


# The following methods are undefined for frozenset:
fs.add(4)
fs.remove(2)
fs.discard(1)
fs.pop()
fs.clear()
fs.update([4, 5])
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Python Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
