Python Type Hints – Type Hints for Function Returning Multiple Values

pythonpython-3.xtype-hinting

How do I write the function declaration using Python type hints for function returning multiple return values?

Is the below syntax allowed?

def greeting(name: str) -> str, List[float], int :

   # do something

   return a,b,c

Best Answer

EDIT: Since Python 3.9 and the acceptance of PEP 585, you should use the built-in tuple class to typehint tuples.


You can use a typing.Tuple type hint (to specify the type of the content of the tuple, if it is not necessary, the built-in class tuple can be used instead):

from typing import Tuple, List

def greeting(name: str) -> Tuple[str, List[float], int]:
    # do something
    return a, b, c
Related Question