class Try_int(int):
def __add__(self,other):
return self+other
def __sub__(self,other):
return self-other
這段代碼是錯的,會陷入無限遞回
可是 int 的__add__方法 也是這么定義的,為什么不會陷入無限遞回??
正確的如下:
class Newint(int):
def __add__(self,other):
return int.__add__(self,other)
def __sub__(self,other):
return int.__sub__(self,other)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/33189.html
上一篇:python類和物件
下一篇:linux下基礎通訊問題
