#PYTHON(DAY11)
frozenset( )
It is immutable and it is hashable. It is also called an immutable set. Since the elements are fixed, unlike sets you can’t add or remove elements from the set. Frozensets are hashable, you can use the elements as a dictionary key or as an element from another set.
synax:
frozenset(iterable)
s = {1,2,3,4,}
a = frozenset(s)
print(a, type(a))
And the output is:
frozenset({1, 2, 3, 4}) <class 'frozenset'>
Note: There is no method like add in frozenset
s = {1,2,3,4,}
a = frozenset(s)
a.add(5)
print(a)
for the above code we get an error saying that ‘frozenset’ object has no attribute ‘add’.
No comments:
Post a Comment