Python编程:Python类的魔术方法
        【摘要】  
  python 递归调用默认上限:1000次 
 
  
  
 
  1、比较运算符:
  
 
  __cmp__(self,other)比较
  
 
  __eq__(self,other)相等
   __lt__(self,other)小于
  
 
  __gt__(self,other)大于
  
 
  
  
 
  2、逻辑运算符:
  
 
  __...
    
    
    
    
  python 递归调用默认上限:1000次 
  
  
 
  
  
  
 
  
 
   1、比较运算符: 
 
 
 
   __cmp__(self,other)比较 
 
 
 
   __eq__(self,other)相等 
  
__lt__(self,other)小于
 
 __lt__(self,other)小于
   __gt__(self,other)大于 
 
 
 
   2、逻辑运算符: 
 
 
 
   __or__(self,other) 
 
 
 
   __and__(self,other) 
  
 
  
3、数学运算符:
 
 3、数学运算符:
   __add__(self,other) + 
 
 
 
   __sub__(self,other)  - 
  
__mul__(self,other) *
 
 __mul__(self,other) *
   __div__(self,other) / 
  
 
  
4、转换为字符串:
 
 4、转换为字符串:
   __str__ 
 
 
 
   __repr__ 
 
 
 
   __unicode__ 
  
 
  
5、展现对象属性:
 
 5、展现对象属性:
   __dir__ 
  
 
  
6、设置对象属性:
__setattr__(self,name,value)
 
  
 
 
 
 6、设置对象属性:
__setattr__(self,name,value)
   7、查询对象属性: 
 
 
 
   __getattr__(self,name) 
  
__getattribute__(self,name)
 
  
8、删除对象属性:
 
 __getattribute__(self,name)
8、删除对象属性:
   __delattr__(self,name) 
  
 
  
 
  
 
  
 
  
 
 
 
 
  文章来源: pengshiyu.blog.csdn.net,作者:彭世瑜,版权归原作者所有,如需转载,请联系作者。
原文链接:pengshiyu.blog.csdn.net/article/details/81049081
        【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
            cloudbbs@huaweicloud.com
        
        
        
        
        
        
        - 点赞
 - 收藏
 - 关注作者
 
            
           
评论(0)