Python class中的other

    科技2022-07-20  132

    定义了一个Point类,类中有计算两点距离的方法,self表示本类,other表示另一个类,可以直接使用属性。

    other参数其他用法 https://www.cnblogs.com/hujingnb/p/10246385.html

    class Point(object):

        def __init__(self, x=0, y=0):

            self.x = x

            self.y = y

        def test(self, other):

            print('this %f' % (sqrt((self.x - other.x)**2 +

                                    (self.y - other.y)**2)))

     

    if __name__ == "__main__":

        a = Point(0, 0)

        b = Point(3, 4)

        a.test(b)

     

    Processed: 0.009, SQL: 8