在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 |
這只是一個實現細節,允許垃圾收集器通知弱引用,它的指涉已被收集,並且不允許訪問它的底層指針。 |