标签:__add__ __init__ call pre 类型 display init __call__ python
class TT: def __init__(self): print "__init__" def __call__(self): print "__call__" def __str__(self): return "__str__" def __int__(self): return "__int__" def __add__(self,other): return "__add__" def __sub__(self,other): return "__sub__" def __mul__(self,other): return "__mul__" def __div__(self,other): return "__div__" def __del__(self): print "析构函数被调用"
在Python中,定义一个类TT如上,那么
如下所示:
obj = TT() # __init__ obj() # __call__ print(int(obj)) # __int__ print(str(obj)) # __str__ print(obj) # __str__ print(obj+50) # __add__ print(obj-50) # __sub__ print(obj*50) # __mul__ print(obj/50) # __div__ del obj # 析构函数被调用
标签:__add__ __init__ call pre 类型 display init __call__ python
原文地址:https://www.cnblogs.com/shiju/p/9519032.html