Flash cards
Review the key moves
1/4
Core idea
What is the main idea behind Python frozenset?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
1Quick choice
Which statement best captures the main point of this lesson?
2Order
Put the learning moves in the order that makes the concept easiest to apply.
Like sets, it contains unique, unordered, unchangeable elements.
frozenset is an immutable version of a set.
Creating a frozenset
frozenset is an immutable version of a set.
Like sets, it contains unique, unordered, unchangeable elements.
Unlike sets, elements cannot be added or removed from a frozenset.
Creating a frozenset
Use the frozenset() constructor to create a frozenset from any iterable.
frozensetFrozenset Methods
Being immutable means you cannot add or remove elements. However, frozensets support all non-mutating operations of sets.
| Method | Shortcut | Description |
|---|---|---|
| copy() | Returns a shallow copy | |
| difference() | - | Returns a new frozenset with the difference |
| intersection() | & | Returns a new frozenset with the intersection |
| isdisjoint() | Returns True if there is NO intersection between two frozensets | |
| issubset() | <= / < | Returns True if this frozenset is a (proper) subset of another |
| issuperset() | >= / > | Returns True if this frozenset is a (proper) superset of another |
| symmetric_difference() | ^ | Returns a new frozenset with the symmetric differences |
| union() | Returns a new frozenset containing the union |