Python frozenset() function

The frozenset() function in Python is used to create frozenset. For example:

x = (32, 43, 53, 534)
y = frozenset(x)
print(y)

The output will be:

frozenset({32, 43, 53, 534})

Python frozenset() function syntax

The syntax of the frozenset() function in Python, is:

frozenset(iterable)

where iterable refers to an iterable object like a listtuple, set, etc.

Python frozenset() function example

The program given below is an example of the frozenset() function in Python.

mylist = ["codes", "cracker", "python", "programming"]
fs = frozenset(mylist)
print(fs)

mydict = {"Day": "Sun", "Month": "Nov", "Year": "2021"}
fs = frozenset(mydict)
print(fs)

The screenshot below shows an example of the output from this Python program, which shows how the frozenset() function works:

python frozenset function

Advantages of the frozenset() function in Python

Disadvantages of the frozenset() function in Python

Python Online Test


« Previous Function Next Function »


Liked this post? Share it!