M
M
mkone1122022-01-06 17:02:23
Python
mkone112, 2022-01-06 17:02:23

Type based branching?

What is the best way to implement similar behavior in python 3.6+?
Pseudocode:

def func(obj)
    if isinstance(obj, dict[str, str]):
        return 'is dict of strings'
    if isinstance(obj, tuple[int]):
        return 'is tuple with one integer'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2022-01-06
@Vindicar

Well you can try functools.singledispatch

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question