Crimes with Python's Pattern Matching
Date: 8/6/2022 · Tags: #python, #tilToday, I learn some wired tricks in Python's pattern matching :lol:
You can match on arrays, dictionaries, and custom objects. To support matching objects, Python uses
isinstance(obj, class)
, which checks
- If
obj
is of typeclass
- If
obj
is a transitive subtype ofclass
- If
class
is an ABC and defines a__subclasshook__
that matches the type ofobj
.