Sunday, May 7, 2023

#PYTHON(DAY11)frozenset()

#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.

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

Building Static Website(part6) HTML Lists

  Building Static Website (part6) HTML Lists Today, let us add some lists to our detailed view section by using html lists. Lists: List is a...