gpt4 book ai didi

python - 为什么我从类似 `instance.method` 的代码中得到了错误的结果?

转载 作者:太空宇宙 更新时间:2023-11-04 07:21:21 25 4
gpt4 key购买 nike

<分区>

这是一个基本问题。我写了下面的代码:

class Point:
def __init__(self,x=0,y=0):
self.x=x
self.y=y
def __str__(self):
return '({0} , {1})'.format(self.x,self.y)
def reflect_x(self):
return Point(self.x,-self.y)

p1=Point(3,4)
p2=p1.reflect_x

print(str(p1),str(p2))
print(type(p1),type(p2))

这里p1的类型和p2的类型是不同的。我只想要 p2 作为 p1 从 x 轴的反射点。我该怎么做?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com