您当前的位置: 首页 >  彭世瑜 Python

Python编程:Python类的魔术方法_彭世瑜_新浪博客

彭世瑜 发布时间:2017-09-03 10:50:51 ,浏览量:3

python 递归调用默认上限:1000次

1、比较运算符:
__cmp__(self,other)比较
__eq__(self,other)相等
__lt__(self,other)小于
__gt__(self,other)大于

2、逻辑运算符:
__or__(self,other)
__and__(self,other)

3、数学运算符:
__add__(self,other) +
__sub__(self,other)  -
__mul__(self,other) *
__div__(self,other) /

4、转换为字符串:
__str__
__repr__
__unicode__

5、展现对象属性:
__dir__

6、设置对象属性:
__setattr__(self,name,value)

7、查询对象属性:
__getattr__(self,name)
__getattribute__(self,name)

8、删除对象属性:
__delattr__(self,name)



关注
打赏
查看更多评论

彭世瑜

暂无认证

  • 3浏览

    0关注

    2727博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录