我试图运行文档中的示例,但出现错误:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
TypeError: Point() accepts 0 positional sub-patterns (2 given)
Run Code Online (Sandbox Code Playgroud)
有人可以解释我在这里做错了什么吗?
class Point():
def __init__(self, x, y):
self.x = x
self.y = y
x, y = 5 ,5
point = Point(x, y)
match point:
case Point(x, y) if x == y:
print(f"Y=X at {x}")
case Point(x, y):
print(f"Not on the diagonal")
Run Code Online (Sandbox Code Playgroud)