在python中新建一个类(class),并用这个类创建实例后,实例会自带这些属性和方法,详细如下表:
1 | __class__ | <class '__main__.my'> | #输出类名称 |
2 | __delattr__ | <method-wrapper '__delattr__' of my object at 0x000001F87E0EB588> |
#装饰器,删除属性 |
3 | __dict__ | {'shit1': 'tobe1', 'shit2': 'tobe2', 'arg': (1, 2, 3), 'args': {'a': 2}} | #所有传入的参数 |
4 | __dir__ | <built-in method __dir__ of my object at 0x000001F87E0EB588> | #此方法会在对相应对象调用 |
5 | __doc__ | simple class by zjw | #输出文档说明,被三个单引号包围的文本 |
6 | __eq__ | <method-wrapper '__eq__' of my object at 0x000001F87E0EB588> | x==y,x.__eq__(y) |
7 | __format__ | <built-in method __format__ of my object at 0x000001F87E0EB588> | 通过 format() 内置函数、扩展、格式化字符串字面值 的求值以及 str.format() 方法调用以生成一个对象的“格式化”字符串表示。 |
8 | __ge__ | <method-wrapper '__ge__' of my object at 0x000001F87E0EB588> | x>=y |
9 | __getattribute__ | <method-wrapper '__getattribute__' of my object at 0x000001F87E0EB588> | #装饰器,获得属性值或者方法 |
10 | __gt__ | <method-wrapper '__gt__' of my object at 0x000001F87E0EB588> | x>y |
11 | __hash__ | <method-wrapper '__hash__' of my object at 0x000001F87E0EB588> | 通过内置函数 hash() 调用以对哈希集的成员进行操作,属于哈希集的类型包括 set 、frozenset 以及 dict 。 |
12 | __init__ | <bound method my.__init__ of <__main__.my object at 0x000001F87E0EB588>> | #初始化函数,在实例 (通过 |
13 | __init_subclass__ | <built-in method __init_subclass__ of type object at 0x000001F87CCFDE78> classmethod | 当所在类派生子类时此方法就会被调用。cls 将指向新的子类。如果定义为一个普通实例方法,此方法将被隐式地转换为类方法。 |
14 | __le__ | <method-wrapper '__le__' of my object at 0x000001F87E0EB588> | x<=y,x.__le__(y) |
15 | __lt__ | <method-wrapper '__lt__' of my object at 0x000001F87E0EB588> | x<y,x.__lt__(y) |
16 | __module__ | __main__ | 通过内置函数 hash() 调用以对哈希集的成员进行操作,属于哈希集的类型包括 set 、frozenset 以及 dict 。 |
17 | __ne__ | <method-wrapper '__ne__' of my object at 0x000001F87E0EB588> | x!=y,x.__ne__(y) |
18 | __new__ | <built-in method __new__ of type object at 0x00007FFE51466D30> | 调用以创建一个 cls 类的新实例。__new__() 是一个静态方法 (因为是特例所以你不需要显式地声明),它会将所请求实例所属的类作为第一个参数。其余的参数会被传递给对象构造器表达式 (对类的调用)。__new__() 的返回值应为新对象实例 (通常是 cls 的实例)。 |
19 | __reduce__ | <built-in method __reduce__ of my object at 0x000001F87E0EB588> | |
20 | __reduce_ex__ | <built-in method __reduce_ex__ of my object at 0x000001F87E0EB588> | |
21 | __repr__ | <method-wrapper '__repr__' of my object at 0x000001F87E0EB588> | 由 repr() 内置函数调用以输出一个对象的“官方”字符串表示。 |
22 | __setattr__ | <method-wrapper '__setattr__' of my object at 0x000001F87E0EB588> | 此方法在一个属性被尝试赋值时被调用。这个调用会取代正常机制(即将值保存到实例字典) |
23 | __sizeof__ | <built-in method __sizeof__ of my object at 0x000001F87E0EB588> | |
24 | __str__ | <method-wrapper '__str__' of my object at 0x000001F87E0EB588> | 通过 str(object) 以及内置函数 format() 和 print() 调用以生成一个对象的“非正式”或格式良好的字符串表示。返回值必须为一个 字符串 对象。 |
25 | __subclasshook__ | <built-in method __subclasshook__ of type object at 0x000001F87CCFDE78> | Python提供了一个类级的子类判断方法:__subclasshook__。该方法定义于类中而非元类中,它要求两个前提:1. 该类为抽象基类;2. 该方法为类方法。这样,__subclasshook__将覆盖元类中的__subclasscheck__产生作用,从而允许我们定义类级的子类校验方式。__subclasshook__可以返回True或False,以及NotImplemented表明未定义。 |
26 | __weakref__ | None |
这只是一个实现细节,允许垃圾收集器通知弱引用,它的指涉已被收集,并且不允许访问它的底层指针。 |