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 frozenset() function in Python, is:

frozenset(iterable)

where iterable refers to an iterable object like list, tuple, set etc.

Python frozenset() Function Example

The program given below is an example of 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 snapshot given below shows the sample output produced by this Python program, demonstrating the frozenset() function:

python frozenset function

Python Online Test


« Previous Function Next Function »



Like/Share Us on Facebook 😋