🐍PyTricks: Dicts can be used to emulate switch/case statements

Fonte: RealPython # Because Python has first-class functions they can # be used to emulate switch/case statements def dispatch_if(operator, x, y): if operator == 'add': return x + y elif operator == 'sub': return x - y elif operator == 'mul': return x * y elif operator == 'div': return x / y else: return … Continue lendo 🐍PyTricks: Dicts can be used to emulate switch/case statements