Python 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:
Contribute to Docs
- 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.
Learn Python on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
- With Certificate
- Beginner Friendly.24 hours