python之面向对象魔法方法

魔法方法描述
__ 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)让对象可以类似函数的方式直接调用执行
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值