【问题标题】:match/case statement raises SyntaxError in PyCharm [closed]match/case 语句在 PyCharm 中引发 SyntaxError [关闭]
【发布时间】:2021-12-23 19:24:57
【问题描述】:

我想使用match/case 语句,但目前 PyCharm 不喜欢它,当我尝试运行此代码时:

def test(action):
    match action:
        case "send":
            pass
        case "create":
            pass
        case "dump":
            pass

它告诉我

    match action:
          ^
SyntaxError: invalid syntax

我使用 python 3.9.1 和 PyCharm 2021.2.3 Pro。关键字matchcase 是蓝色的,所以我猜PyCharm 可以识别它们但无法运行它。我在这里错过了什么?

【问题讨论】:

    标签: python pycharm python-3.9


    【解决方案1】:

    您使用的 Python 版本低于 3.10。

    PEP 634: Structural Pattern Matching 在 python 3.10 中引入。见What’s New In Python 3.10 了解更多信息。

    【讨论】:

      猜你喜欢
      • 2021-11-06
      • 2022-09-28
      • 2021-03-02
      • 1970-01-01
      • 2012-06-18
      • 1970-01-01
      • 1970-01-01
      • 2022-11-02
      相关资源
      最近更新 更多