构造器
__init__(self[,...])
类在实例化的时候自动被调用的方法。
__new__(cls[,...])
在类的实例化之前调用,根据需要可重写。
析构器
__del__(self)
当对象被销毁(Python的垃圾回收机制)时,该方法被调用。
算数运算
方法 | 解释 |
---|---|
__add__(self,other) |
定义加法的行为:+ |
__sub__(self,other) |
定义减法的行为:- |
__mul__(self,other) |
定义乘法的行为:* |
__truediv__(self,other) |
定义真除法的行为:/ |
__floordiv__(self,other) |
定义整数除法的行为:// |
__mod__(self,other) |
定义取模算法的行为:% |
__pow__(self,other[,modulo]) |
定义power()调用或者**运算时的行为 |
__lshift__(self,other) |