文章目录
模式匹配 match语句(仅在 Python 3.10及以上版本 中可用)
- Python 3.10 及以上版本中才引入了 match 语句
- 用于简化复杂的条件判断和数据解构;类似于其他语言中的 switch-case 语句,但功能更强大,支持 结构化模式匹配 (Structural Pattern Matching)
1. 基本语法
# match subject:
# case pattern1:
# #当 subject 匹配 pattern1 时执行的代码
# case pattern2:
# #当 subject 匹配 pattern2 时执行的代码
# ...
# case _:
订阅专栏 解锁全文
432

被折叠的 条评论
为什么被折叠?



