1

Let's say that my function can accept parameter b to be either an int or a list

def foo_fun(a: int, b: ??)->int:
   if isinstance(b,list):
       do something
   else 
       do something else

How can i use type hinting with this particular setting?

Thanks

1 Answer 1

2

You seems to be describing Union.

For example:

from typing import Union


def foo_fun(a: int, b: Union[int, list]) -> int:
   if isinstance(b, list):
       do something
   else 
       do something else
1
  • 1
    thanks sorry for my ignorance. i didn't know there was a module for type hinting support. Thanks Commented Mar 18, 2020 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.