AI engineering glossary · Python advanced
What is union type?
Union type: A type hint stating that a value may be one of several types, written Union[int, str] or int | str. It documents flexible parameters and lets checkers verify each case is handled.
Union type: an example
def parse(x: int | str) -> int: accepts a number or a numeric string.
Related terms
- Optional type
- Type hint
- Literal type
- mypy
More Python advanced terms
Where you learn it
Union type is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.