python为什么“ __add__”函数可以到达该类中的其他任何函数?

im practicing on a matrix class with matrix operations, and there is something i dont understand about the __add__ function. i defined a funcion "row_addition" that does addition between rows, so why it can reach it?

because i wrote it only after the __add__ function. normally when i call a function that is not yet defined it doesn't work, so why it does work here?

def __add__(self, other):
    cont = []
    mat = Matrix(self.get_rows(),self.get_collums(),cont)
    row_count = 0
    while row_count < len(self.content):
        cont.append(self.row_addition(self.content[row_count], other.content[row_count]))
        row_count += 1
    return mat

非常感谢你!

评论