In this article, we will be discussing frozenset() which is an inbuilt function provided by Python language.
frozenset() function:
The task of this function is to freeze the iterable objects provided and make them unchangeable So that, no changes take place. Also, frozenset() is somehow similar to set(). However, it differs only in making the iterable objects unalterable. Moreover, this function does not guarantee to maintain the order of elements.
Syntax: frozenset(iterable object) Input Parameter(optional): Any iterable object such as, list, set, tuple etc. If we try to change the frozenset value, it will throw an error. If we don't pass anything to this function then it simple return empty frozenset object. Return: frozen set object.
Let’s see the examples:
Example 1:
x = frozenset() print(x)
Output:
frozenset()
Example 2:
# list a = ['abc', 'def'] x = frozenset(a) print(x)
Output:
frozenset({'abc', 'def'})
Example 3:
# set a = {1,2,3} x = frozenset(a) print(x)
Output:
frozenset({1, 2, 3})
Example 4:
a = ['abc', 'def'] x = frozenset(a) x[1] = "blue"
Output:
Traceback (most recent call last): File "", line 1, in x[1] = "blue" TypeError: 'frozenset' object does not support item assignment