上一页 1 ··· 54 55 56 57 58 59 60 61 62 ··· 75 下一页
摘要: 目录 一、小结 曾经我幼稚的以为认识了python的__init__()方法就相当于认识了类构造器,结果,__new__()方法突然出现在我眼前,让我突然认识到原来__new__才是老大。为什么这么说呢? 我们首先得从__new__(cls[,...])的参数说说起,__new__方法的第一个参数是 阅读全文
posted @ 2019-11-21 21:15 ABDM 阅读(53) 评论(0) 推荐(0) 编辑
摘要: 目录 一、__call__ 一、__call__ 对象后面加括号时,触发执行。 注:构造方法的执行是由创建对象触发的,即:对象 = 类名() ;而对于 __call__ 方法的执行是由对象后加括号触发的,即:对象() 或者 类()() class Foo: def __init__(self): p 阅读全文
posted @ 2019-11-21 20:48 ABDM 阅读(37) 评论(0) 推荐(0) 编辑
摘要: 目录一、__doc__ 一、__doc__ 返回类的注释信息 class Foo: '我是描述信息' pass print(Foo.doc) 我是描述信息 该属性无法被继承 class Foo: '我是描述信息' pass class Bar(Foo): pass print(Bar.__doc__ 阅读全文
posted @ 2019-11-21 20:32 ABDM 阅读(26) 评论(0) 推荐(0) 编辑
摘要: 目录 一、什么是__slots__ 二、为什么用__slots__ 三、刨根问底 一、什么是__slots__ __slots__是一个类变量,变量值可以是列表,元祖,或者可迭代对象,也可以是一个字符串(意味着所有实例只有一个数据属性) 使用点来访问属性本质就是在访问类或者对象的__dict__属性 阅读全文
posted @ 2019-11-21 19:54 ABDM 阅读(50) 评论(0) 推荐(0) 编辑
摘要: 目录 一、__del__ 一、__del__ __del__也称之为析构方法 __del__会在对象被删除之前自动触发 class People: def __init__(self, name, age): self.name = name self.age = age self.f = open 阅读全文
posted @ 2019-11-21 19:53 ABDM 阅读(47) 评论(0) 推荐(0) 编辑
摘要: 目录 一、__format__ 一、__format__ 自定制格式化字符串 date_dic = { 'ymd': '{0.year}:{0.month}:{0.day}', 'dmy': '{0.day}/{0.month}/{0.year}', 'mdy': '{0.month}-{0.day 阅读全文
posted @ 2019-11-21 19:52 ABDM 阅读(51) 评论(0) 推荐(0) 编辑
摘要: 目录 一、__setitem__ 二、__getitem__ 三、__delitem__与__delattr__ class Foo: def __init__(self, name): self.name = name def __getitem__(self, item): print('get 阅读全文
posted @ 2019-11-21 19:51 ABDM 阅读(53) 评论(0) 推荐(0) 编辑
摘要: 目录 一、描述符 二、描述符的作用 2.1 何时,何地,会触发这三个方法的执行 三、两种描述符 3.1 数据描述符 3.2 非数据描述符 四、描述符注意事项 五、使用描述符 5.1 牛刀小试 5.2 拔刀相助 5.3 磨刀霍霍 5.4 大刀阔斧 5.4.1 类的装饰器:无参 5.4.2 类的装饰器: 阅读全文
posted @ 2019-11-21 19:50 ABDM 阅读(58) 评论(0) 推荐(0) 编辑
摘要: 目录 一、__setattr__ 二、__delattr__ 三、 __getattr__ class Foo: x = 1 def __init__(self, y): self.y = y def __getattr__(self, item): print(' > from getattr:你 阅读全文
posted @ 2019-11-21 19:49 ABDM 阅读(48) 评论(0) 推荐(0) 编辑
摘要: 目录 一、__getattr__ 二、__getattribute__ 三、__getattr__与__getattribute__ 一、__getattr__ 不存在的属性访问,触发__getattr__ class Foo: def __init__(self, x): self.x = x d 阅读全文
posted @ 2019-11-21 19:49 ABDM 阅读(51) 评论(0) 推荐(0) 编辑
上一页 1 ··· 54 55 56 57 58 59 60 61 62 ··· 75 下一页