ID EN
Built-in Types

X | Y | ...

Python 3.11

Defines a union object which holds types X, Y, and so forth. X | Y means either X or Y. It is equivalent to typing.Union[X, Y]. For example, the following function expects an argument of type int or float:

Syntax

PYTHON
X | Y | ...

Examples

Example 1
PYTHON
def square(number: int | float) -> int | float:
    return number ** 2

See Also

int float