Python Tutorial Python Advanced Python Resources Python Libraries
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

Python frozenset() Function



The Python frozenset() function returns frozenset object which contains all unique elements of an specified iterable. Along with this, elements of the frozenset object can not be changed (just like set).

Syntax

frozenset(iterable)

Parameters

iterable Required. iterable object like list, tuple, set, string , dictionary and range() etc.

Example:

In the example below, frozenset() function is used to create a frozenset object from a given list.

MyList = [1, 5, 10, 10, 10, 15]
x = frozenset(MyList)
print(x)

The output of the above code will be:

frozenset({1, 5, 10, 15})

Example: Change elements of a frozenset object

As mentioned before, elements of frozenset object can not be changed.

MyList = [1, 5, 10, 10, 10, 15]
x = frozenset(MyList)
x[1] = 100

The output of the above code will be:

Traceback (most recent call last):
  File "Main.py", line 3, in <module>
    x[1] = 100
TypeError: 'frozenset' object does not support item assignment

❮ Python Built-in Functions

5