What does vertical bar "|" (pipe) in function arguments type annotations mean?

Viewed 1525

I came across function with signature like this:

def get_quantile(numbers: List[float], q: float | int ) -> float | int | None :

What does it mean?

It's a syntax error on my python 3.8. Do I need to import something from future to make it work?

2 Answers

According to PEP 604, | will be used to designate union types from Python 3.10.

So float | int will mean Union[float, int], i.e. a float or an int.

It means or. So q: float | int means that q may either be a float or an int.

Related