魔法方法 | 描述 |
---|---|
__ new__(cls) | 创建对象自动调用 |
__init __(self) | 给创建的对象属性赋值,自动调用 |
__ str __(self) | 当直接 print(对象引用变量)自定义的输出字符串数据 |
__ repr __(self) | 当其他对象引用使用当前对象时打印展示自定义字符传数据 |
__ gt __(self, other) | gt:grant than 大于,描述的是操作符号:>判断当前对象是否大于 other 对象 |
__ lt __(self, other) | lt: less than 小于,描述的是操作符号:< |
__ ge __(self, other) | ge: grant or equals 大于等于:>= |
__ le __(self, other) | le: less or equals 小于等于 |
__ eq __(self, other) | eq: equals 是否相等 == |
__ ne __(self, other) | ne: not equals 是否不相等 != |
__ add __(self, other) | + |
__ sub __(self, other) | - |
__ mul __(self, other) | * |
__ div __(self, other) | / |
__ floordiv __(self, other) | // |
__ pow __(self, other) | ** |
__ iadd __(self, other) | += |
__ isub __(self, other) | -= |
__ imul __(self, other) | *= |
__ idiv __(self, other) | /= |
__ ifloordiv __(self, other) | //= |
__ ipow __(self, other) | **= |
__ call __(self) | 让对象可以类似函数的方式直接调用执行 |
python之面向对象魔法方法
最新推荐文章于 2022-02-18 23:19:55 发布