frozenset()
BrandonDusch580 total contributions
Published May 23, 2022
Contribute to Docs
The built-in frozenset()
function returns a new frozenset using an optional iterable object such as a string or list.
Frozensets are a specific type of set that are immutable. Like tuples, their contents are frozen and cannot be changed after creation.
Syntax
frozenset(iterable)
The iterable
parameter is optional and must be a hashable object. If nothing is passed into the frozenset()
function, an empty frozenset is created.
Example
In the following example, a frozenset of frozen_objects
is created:
frozen_objects = frozenset(['ice cube', 'glacier', 'frozen_set'])print(frozen_objects)print(type(frozen_objects))
The following output will look like this:
frozenset({'glacier', 'ice cube', 'frozen_set'})<class 'frozenset'>
Codebyte Example
In the example below, the frozenset()
function is used to create a new frozenset called continents
:
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.