Function Details: frozenset

Description


Returns an immutable set object initialized from iterable.


Extended Description


The frozenset() function returns an immutable set object. Like sets, frozensets are unordered collections of unique elements, but unlike sets, frozensets are immutable and hashable. This makes them suitable for use as dictionary keys or as elements of other sets. If no argument is passed, it returns an empty frozenset.


Exceptions


  • TypeError: If the iterable contains unhashable objects

Read More about frozenset from Python Documentation

Function Signature


frozenset(iterable: Optional[Iterable] = None) -> frozenset

Module: builtins

Class: frozenset

Parameters


iterable: An optional iterable object (e.g., list, tuple, set) to initialize the frozenset. If omitted, returns an empty frozenset.


Parameter List


  • iterable: Optional[Iterable]

Return


Returns a new frozenset object containing unique elements from the input iterable.


Return Type


frozenset

Output

Explanation

This example shows creating frozensets from a list with duplicates, a string, and an empty frozenset.