我有这段代码可以计算两个坐标之间的距离。这两个函数都在同一个类中。
但是,如何在函数isNear
中调用函数distToPoint
呢?
class Coordinates:
def distToPoint(self, p):
"""
Use pythagoras to find distance
(a^2 = b^2 + c^2)
"""
...
def isNear(self, p):
distToPoint(self, p)
...
最佳答案
由于这些是成员函数,因此将其作为实例上的成员函数调用,self
。
def isNear(self, p):
self.distToPoint(p)
...
关于python - 如何在类中调用函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5615648/