Skip to content

Instantly share code, notes, and snippets.

@Hultner
Created March 11, 2021 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hultner/0a6a608b3f66193498c96efc072c5b20 to your computer and use it in GitHub Desktop.
Save Hultner/0a6a608b3f66193498c96efc072c5b20 to your computer and use it in GitHub Desktop.
Python Structural Pattern Matching.
Python 3.10.0a6+ (heads/master:87f649a409, Mar 11 2021, 16:29:20) [Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> status_code = 200
>>> match status_code:
... case 404: print("Not found")
... case 200: print("Ok")
... case _: raise ValueError("Can't handle status code")
...
Ok
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment