|
各位大佬,我在学习魔法方法时,发现了一个问题,
1.
class Try_int(int):
def __add__(self, other):
return int(self) + int(other)
2
class Try_int(int):
def __add__(self, other):
return self + other
为什么第一种可以正常运行,而第二种会无限递归?另外,我用help(int)查了add的定义。发现如下定义:
| __add__(self, value, /)
| Return self+value.
这个和我的第二个代码不是一样么
|
|