Built-in Functions and Types
frozenset()
Build an immutable set of distinct hashable elements. Unlike set, a frozenset can serve as a dictionary key or member of another set. It supports non-mutating set operations but has no add or remove method. Its iteration order is not guaranteed.
Formal Syntax & Structure
python syntaxpython
frozenset(iterable=(), /)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| iterable | iterable of hashable objects | Elements to collect; defaults to empty. |
Return Value
frozenset
An immutable hashable set; equal frozensets have equal hashes.
Working Example
Example Snippetpython
permissions = frozenset(["read", "write", "read"])labels = {permissions: "editor"}print(sorted(permissions))print(labels[frozenset(["write", "read"])])