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.

Level: intermediateTopic: Python advanced

Union type: an example

def parse(x: int | str) -> int: accepts a number or a numeric string.

Related terms

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.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.