frozenset()

Published May 24, 2024
Contribute to Docs

The frozenset() function is an immutable implementation of a set object. After its creation, the elements can’t be changed, added, or removed and thus, it is given the name frozenset(). This function is hashable and it can be used as a key in a dictionary.

Syntax

frozenset(iterable)
  • iterable: The container having the values to be stored in the frozenset.

Example

The below example demonstrates the use of the frozenset() function:

fs1 = frozenset([1, 2, 3, 4])
fs2 = frozenset({5, 6, 7, 8})
print(fs1)
print(fs2)

The above code produces the following output:

frozenset({1, 2, 3, 4})
frozenset({8, 5, 6, 7})

Codebyte Example

Here is a codebyte example showing the usage of the frozenset() function:

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn Python on Codecademy