文章目录 模式匹配 match语句(仅在 Python 3.10及以上版本 中可用) 1. 基本语法 2. 基本匹配操作 2.1 匹配常量 2.2 匹配变量 2.3 匹配元组 2.4 匹配列表 2.5 匹配字典 2.6 条件匹配 3. 应用场景 模式匹配 match语句(仅在 Python 3.10及以上版本 中可用) Python 3.10 及以上版本中才引入了 match 语句 用于简化复杂的条件判断和数据解构;类似于其他语言中的 switch-case 语句,但功能更强大,支持 结构化模式匹配 (Structural Pattern Matching) 1. 基本语法 # match subject: # case pattern1: # #当 subject 匹配 pattern1 时执行的代码 # case pattern2: # #当 subject 匹配 pattern2 时执行的代码 # ...