September 2026
1051 pages
35h 4m
English
A set is a unordered collection of elements in which each element may be contained only once. In Python, there are two basic data types for representing sets: set for a mutable set and frozenset for an immutable set.
Note that whether a mutable or an immutable set is instantiated, a set can contain only immutable elements. Table 13.1 provides an overview of the basic data types and their mutability. For example, if you try to create a set that should contain a list as an element, the interpreter reports a corresponding error:
>>> set([1, 2, list()])Traceback (most recent call last): File "<python-input-3>", line 1, in <module> set([1, 2, list()]) ~~~^^^^^^^^^^^^^^^^TypeError: cannot use ...
Read now
Unlock full access