小编And*_*tta的帖子

Python 结构模式匹配

我无法运行此代码:

match shape:
    case Point(x, y):
        ...
    case Rectangle(x, y, _, _):
        ...
print(x, y)
Run Code Online (Sandbox Code Playgroud)

match在python中找不到关键字,

我在这里找到它:https : //www.python.org/dev/peps/pep-0622/#the-match-statement

...任何的想法??

更新:刚刚看到你的答案,像我这样的新 python 开发人员可能会犯同样的错误,所以我会把这个问题留给可能需要的每个人......谢谢你们,我真的很感谢你们的努力!

python functional-programming python-3.10 structural-pattern-matching

5
推荐指数
2
解决办法
1190
查看次数