Type unions: X | Y and X | None
In type annotations, the union X | Y means a value of type X or Y, while the union X | None also permits None. Annotations describe allowed values but do not automatically enforce runtime checks.
CKTIS / Knowledge base
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
In type annotations, the union X | Y means a value of type X or Y, while the union X | None also permits None. Annotations describe allowed values but do not automatically enforce runtime checks.
Assignment unpacking binds items from an iterable to targets, while call unpacking supplies separate arguments to a function.
The *args parameter collects excess positional arguments into a tuple, while **kwargs collects excess keyword arguments into a dictionary. They let a function accept a variable number of arguments.
The type of the singleton None is available as types.NoneType and also via type(None).