What is a frozen set in Python?

A set is an unordered or unindexed “bag” of unique values.

A single set can contain values of any immutable datatype, meaning the values can’t be changed. A set itself is a mutable object, i.e, an object that can be changed after it is created.

Frozen sets

Frozen sets in Python return an object that is unchangeable. They are referred to as a set because the set is inherent, not mutable.

You can use the frozenset() function to get a non-mutable object.

Code

lst = ["a", "b","c"]
print("Normal List")
print(lst)
frozen_set = frozenset(lst)
print("\nFrozen Set")
print(frozen_set)

Free Resources