Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 507
Kroshka Kartoshka Avatar asked Dec 02 '25 09:12

Kroshka Kartoshka


1 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.

like image 78
khelwood Avatar answered Dec 04 '25 22:12

khelwood



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!