The frozenset()
function is used to create an immutable frozenset object. A frozenset is an unordered collection of unique elements, similar to a set, but it is immutable, meaning its elements cannot be modified once it is created.
The frozenset()
function takes an iterable as its argument and returns a new frozenset object containing the elements from the iterable. If no argument is provided, an empty frozenset is returned.
frozenset(iterable = None)
copy
iterable |
The iterable argument to be casted into a frozenset. If it is not given, an empty frozenset will be returned. |
If no argument is given, the function returns an empty frozenset. Otherwise, the function returns a frozenset with all the unique elements from the given iterable.
Frozensets are especially useful when you need an immutable set-like object that can be used as a dictionary key or as an element in another set. Their immutable nature also makes them more efficient than 'normal' sets if we do not intend to modify the resulting set.