frozenset()
fronzenset(my_iterable)
my_iterable : This is an iterable object like List , tuple , set
Output is unchangeable frozenset object. This object is immutable ( what is immutable ? )
Using List
my_list=[1,2,3]
my_list=frozenset(my_list)
print(my_list) # frozenset({1, 2, 3})
We will try to change one element
my_list=[1,2,3]
my_list=frozenset(my_list)
my_list[1]=8
print(my_list) # frozenset({1, 2, 3})
Above code will generate error saying TypeError: 'frozenset' object does not support item assignment
Using tuple
my_tuple=(1,2,3)
my_tuple=frozenset(my_tuple)
my_tuple[1]=5
Above code will generate error saying TypeError: 'frozenset' object does not support item assignment
One more example
my_tuple=(1,2,3)
my_tuple +=(4,5)
print(my_tuple)
my_tuple=frozenset(my_tuple)
my_tuple +=(6,7)
Above code will generate error saying TypeError: unsupported operand type(s) for +=: 'frozenset' and 'tuple'
« Python
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com