Рет қаралды 220,480
What's the purpose of the match statement in Python?
The match statement is commonly mistaken for being Python's way of adding a switch-case statement. NOPE! This is not the intended purpose of the match statement, and it does not have similar performance benefits. Let's see what the match statement is REALLY for by parsing concrete syntax trees (CSTs).
― mCoding with James Murphy (mcoding.io)
Source code: github.com/mCodingLLC/VideosS...
libcst: libcst.readthedocs.io/en/late...
AST linting vid: • Python AST Parsing and...
Structural pattern matching vid: • The Hottest New Featur...
SUPPORT ME ⭐
---------------------------------------------------
Patreon: / mcoding
Paypal: www.paypal.com/donate/?hosted...
Other donations: mcoding.io/donate
Top patrons and donors: Jameson, Laura M, Dragos C, Vahnekie, John Martin, Casey G
BE ACTIVE IN MY COMMUNITY 😄
---------------------------------------------------
Discord: / discord
Github: github.com/mCodingLLC/
Reddit: / mcoding
Facebook: / james.mcoding
CHAPTERS
---------------------------------------------------
0:00 Intro
0:20 Switch case?
2:52 ASTs and CSTs
4:14 True, True, True
4:46 Visiting the CST
5:50 Matching the CST
7:50 Addressing complexity