Python 类的特殊方法.pdfVIP

  • 2
  • 0
  • 约3.69千字
  • 约 4页
  • 2026-06-10 发布于浙江
  • 举报

Python类类的的特特殊殊方方法法

1.__repr__

__str__

自我描述方法,repr更加倾向于用在详细信息的miaosh

str一般提供给终端用户显内容

2._del_

释放对象占用的内存。

3.__dir__

用于列出对象所有属性和方法

4.__dict__

查看对象内部存储的所有属性名和属性值组成的字典

5.__getattr__

访问对象的属性,而且该属性不存在的时候被调用。

classRectangel:

def__init__(self,width,height):

self.width=width

self.height=height

def__getattr__(self,name):

ifname==size:

returnself.width,self.height

el

文档评论(0)

1亿VIP精品文档

相关文档