Since python is dynamically typed, of course we can do something like this:
def f(x):
return 2 if x else \"s\"
But is this the way pyth
the type itself does not exist because Python is just a dynamically typed language, however, in newer Python versions, Union Type is an option for Type Hinting,
from typing import Union,TypeVar
T = TypeVar('T')
def f(x: T) -> Union[str, None]:
if x:
return "x"
you can use that to annotate your code, thus enabling IDE/Editor level syntax checking.