\( \newcommand{\NOT}{\neg} \newcommand{\AND}{\wedge} \newcommand{\OR}{\vee} \newcommand{\XOR}{\oplus} \newcommand{\IMP}{\Rightarrow} \newcommand{\IFF}{\Leftrightarrow} \newcommand{\TRUE}{\text{True}\xspace} \newcommand{\FALSE}{\text{False}\xspace} \newcommand{\IN}{\,{\in}\,} \newcommand{\NOTIN}{\,{\notin}\,} \newcommand{\TO}{\rightarrow} \newcommand{\DIV}{\mid} \newcommand{\NDIV}{\nmid} \newcommand{\MOD}[1]{\pmod{#1}} \newcommand{\MODS}[1]{\ (\text{mod}\ #1)} \newcommand{\N}{\mathbb N} \newcommand{\Z}{\mathbb Z} \newcommand{\Q}{\mathbb Q} \newcommand{\R}{\mathbb R} \newcommand{\C}{\mathbb C} \newcommand{\cA}{\mathcal A} \newcommand{\cB}{\mathcal B} \newcommand{\cC}{\mathcal C} \newcommand{\cD}{\mathcal D} \newcommand{\cE}{\mathcal E} \newcommand{\cF}{\mathcal F} \newcommand{\cG}{\mathcal G} \newcommand{\cH}{\mathcal H} \newcommand{\cI}{\mathcal I} \newcommand{\cJ}{\mathcal J} \newcommand{\cL}{\mathcal L} \newcommand{\cK}{\mathcal K} \newcommand{\cN}{\mathcal N} \newcommand{\cO}{\mathcal O} \newcommand{\cP}{\mathcal P} \newcommand{\cQ}{\mathcal Q} \newcommand{\cS}{\mathcal S} \newcommand{\cT}{\mathcal T} \newcommand{\cV}{\mathcal V} \newcommand{\cW}{\mathcal W} \newcommand{\cZ}{\mathcal Z} \newcommand{\emp}{\emptyset} \newcommand{\bs}{\backslash} \newcommand{\floor}[1]{\left \lfloor #1 \right \rfloor} \newcommand{\ceil}[1]{\left \lceil #1 \right \rceil} \newcommand{\abs}[1]{\left | #1 \right |} \newcommand{\xspace}{} \newcommand{\proofheader}[1]{\underline{\textbf{#1}}} \)

B.4 typing

Built-in collection types (no import required)

Type Description
dict[T1, T2]

A dictionary whose keys have type T1 and whose values have type T2.

Example: {'a': 1, 'b': 2} has type dict[str, int].

list[T]

A list whose elements all have type T.

Example: [1, 2, 3] has type list[int].

set[T]

A set whose elements all have type T.

Example: {'hi', 'bye'} has type set[str].

tuple[T1, T2, ...]

A tuple whose first element has type T1, second element has type T2, etc.

Example: ('hello', True, 3.4) has type tuple[str, bool, float].

Types imported from the typing module

Reference: https://docs.python.org/3.10/library/typing.html.

Type Description
Any A value that could be of any type. (Used as a placeholder when a variable’s type could be anything, or is unknown.)
Callable[[T1, T2, ...], Tr]

A function whose parameters have type T1, T2, etc., and whose return type is Tr.

Example: the function

def f(x: int, y: str) -> bool:
    # Body omitted

has type Callable[[int, str], bool].

Optional[T] Synonym of Union[T, None].
Union[T1, T2, ...]

A value whose type is one of T1, T2, etc.

Example: both 1 and 'hello' are instance of type Union[int, str].