求助大佬,关于__add__
class Nint(int):def __radd__(self, other):
return int.__sub__(self, other)
a = Nint(5)
b = Nint(3)
print(a + b)# 答案是8
print(1 + b)# 答案是2,为什么? 1. a + b 调用 a.__add__(b),由于 a 继承自 int,所以有 __add__ 。返回 5+3 。
2. https://fishc.com.cn/thread-167400-1-1.html 你好,小张。多多指教
页:
[1]