# Union Type

*noun*

say it: **“YOON-yun TYP”** **/ˈjunjən taɪp/**

A type hint saying a value may be one of several types, written with a vertical line, such as int | str or float | None.

## What is a **union type**?

A **union type** (`int | str`) says a value can be one of several types.

```python
def format_id(order_id: int | str) -> str:
    return f"#{order_id}"

print(format_id(42))      # #42
print(format_id("A-17"))  # #A-17
```

## In a sentence

- “The **union type** int | str lets format_id take 42 or "A-17".”
- “find_order returns a **union type**, Order | None, because the order may not exist.”

Level: Freelancer · [More Python terms at this level](https://www.ask-codey.com/glossary?category=python&level=4)

Updated: November 19, 2026

Source: https://www.ask-codey.com/glossary/union-type
