在Python中,子类可以重写父类的成员方法,包括特殊方法(如`__init__`、`__str__`等)和一般方法。重写成员方法时,子类的方法体将覆盖父类的方法体。如果子类需要调用父类的方法,可以使用`super()`函数。
`__init__(self, [args...])`:构造函数,用于初始化新创建的对象。
`__del__(self)`:析构函数,当对象被销毁时调用。
`__str__(self)`:定义对象的字符串表示形式。
`__repr__(self)`:定义对象的官方字符串表示形式,通常用于调试。
`__getitem__(self, key)`:定义获取容器中指定素的行为。
`__setitem__(self, key, value)`:定义设置容器中指定素的行为。
`__delitem__(self, key)`:定义删除容器中指定素的行为。
`__add__(self, other)`:定义加法的行为。
`__sub__(self, other)`:定义减法的行为。
`__mul__(self, other)`:定义乘法的行为。
`__truediv__(self, other)`:定义除法的行为。
`__floordiv__(self, other)`:定义整除的行为。
`__mod__(self, other)`:定义取模的行为。
`__pow__(self, other)`:定义乘方的行为。
`__lshift__(self, other)`:定义左移的行为。
`__rshift__(self, other)`:定义右移的行为。
`__and__(self, other)`:定义按位与的行为。
`__or__(self, other)`:定义按位或的行为。
`__xor__(self, other)`:定义按位异或的行为。
`__neg__(self)`:定义负号的行为。
`__pos__(self)`:定义正号的行为。
`__abs__(self)`:定义绝对值的行为。
`__invert__(self)`:定义按位取反的行为。
`__lshift__(self, other)`:定义左移的行为。
`__rshift__(self, other)`:定义右移的行为。
`__eq__(self, other)`:定义等于的行为。
`__ne__(self, other)`:定义不等于的行为。
`__lt__(self, other)`:定义小于的行为。
`__le__(self, other)`:定义小于等于的行为。
`__gt__(self, other)`:定义大于的行为。
`__ge__(self, other)`:定义大于等于的行为。
`__bool__(self)`:定义布尔值的行为。
`__len__(self)`:定义对象长度的行为。
`__getitem__(self, key)`:定义获取容器中指定素的行为。
`__setitem__(self, key, value)`:定义设置容器中指定素的行为。
`__delitem__(self, key)`:定义删除容器中指定素的行为。
`__add__(self, other)`:定义加法的行为。
`__sub__(self, other)`:定义减法的行为。
`__mul__(self, other)`:定义乘法的行为。
`__truediv__(self, other)`:定义除法的行为。
`__floordiv__(self, other)`:定义整除的行为。
`__mod__(self, other)`:定义取模的行为。
`__pow__(self, other)`:定义乘方的行为。
`__lshift__(self, other)`:定义左移的行为。
`__rshift__(self, other)`:定义右移的行为。
`__and__(self, other)`:定义按位与的行为。
`__or__(self, other)`:定义按位或的行为。
`__xor__(self, other)`:定义按位异或的行为。
`__neg__(self)`:定义负号的行为。
`__pos__(self)`:定义正号的行为。
`__abs__(self)`:定义绝对值的行为。
`__invert__(self)`:定义按位取反的行为。
`__lshift__(self, other)`:定义左移的行为。
`__rshift__(self, other)`:定义右移的行为。
`__eq__(self, other)`:定义等于的行为。
`__ne__(self, other)`:定义不等于的行为。
`__lt__(self, other
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://sigusoft.com/bj/139918.html