bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths

Loading lesson path

Learn/Python/Foundations
Python•Foundations

Python 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.

frozenset

Frozenset Methods

Being immutable means you cannot add or remove elements. However, frozensets support all non-mutating operations of sets.

MethodShortcutDescription
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

Previous

Python - Join Sets

Next

Python - Set Methods