Python frozenset() function
Discover the Python frozenset() function to create immutable sets. Learn how to use frozensets in Python with this comprehensive guide at rrtutors.com.
In this post, we are going to look at the Python frozenset() function. A Python frozenset() function is a built-in function for generating frozenset objects. A frozenset object in Python is an immutable collection of objects whose contents cannot be modified or altered.
Syntax
The following is the syntax of the frozenset() function:
class frozenset([iterable]) |
where the iterable can be a set, a dictionary, or a tuple structure.
The function frozenset() returns a new set of the frozen object, which contains the objects of the iterable element.
Example
In the following example, we are going to create a frozenset from a turple using the frozenset() function
a = ('I', 'love', 'Python', 'so', 'much', 1,0,0) x = frozenset(a) print(x) |
Output:
frozenset({0, 1, 'so', 'Python', 'much', 'love', 'I'}) |