Facebook Page Twitter Page LinkedIn Page
× Python Tutorial Python Advanced Python Resources Python Libraries


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 below example, 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:

TypeError: 'frozenset' object does not support item assignment

❮ Python Built-in Functions