Frozen Set
Python provides another built-in type called a frozenset. Frozensets are exactly the same as set in all aspects except that they are immutable. You can perform all operations similar to sets except change or modifying operations such as add()
and update()
.
You can create a frozenset with frozenset(<iter>)
method.
Frozensets are useful in situations where you want to use a set, but you need an immutable object. For example, you can’t define a set whose elements are also sets, because set elements must be immutable:
Sometimes, it happens that you need to define a set of sets, you can create set of sets if the elements are frozensets because frozensets are immutable.
Last updated