原创 python __運算__

https://docs.python.org/3/reference/datamodel.html#object.lt object.__lt__(self, other) object.__le__(self, other)

原创 python `__format__`

https://docs.python.org/3/reference/datamodel.html#object.format object.__format__(self, format_spec) 當對象作爲參數傳給form

原创 python 函數類型

屬性 描述 __doc__ 方法的文檔 __name__ 方法的名稱 __qualname__ __module__ 方法所在的模塊名 __defaults__ A tuple containing

原创 python `__del__`

https://docs.python.org/3/reference/datamodel.html#object.del object.__del__(self) 當實例銷燬的時候調用

原创 python 可變對象參數

可變對象如list,tuple,dictionary或者instances,在一個函數的默認參數中只會被初始化一次 . def f(a, L=[]): L.append(a) return L print(f(1

原创 python `__hash__`

https://docs.python.org/3/reference/datamodel.html#object.hash object.__hash__(self) 作爲參數傳給hash()函數時調用

原创 python `__repr__`

https://docs.python.org/3/reference/datamodel.html#object.repr object.__repr__(self) 調用repr()方法將自己轉換爲字符,給eval來操作

原创 python `__bool__`

https://docs.python.org/3/reference/datamodel.html#object.bool object.__bool__(self) bool操作時調用.必須返回False或者True.如果沒有

原创 python `__bytes__`

https://docs.python.org/3/reference/datamodel.html#object.bytes object.__bytes__(self) 將對象轉換爲二進制字符串

原创 python 抽象類和接口

可以通過普通類實現接口,但是並沒有起到規範作用,繼承者可以選擇實現或不實現 # 普通類定義接口 # class Animal(object): # def say(self): # pass # d

原创 python 保留的類標識符

1._*:The special identifier _ is used in the interactive interpreter to store the result of the last evaluation; it

原创 python `__call__`

https://docs.python.org/3/reference/datamodel.html#object.call object.__call__(self[, args...]) Called when the ins

原创 python metaclass應用

1.abs實現抽象類就是需要修改metaclass 2.django中的orm也是修改metaclass 3.通過mytype創建對象,實現繼承 class MyType(type): def __init__(self,

原创 python type

https://docs.python.org/3/library/functions.html#type 1.type(object) class type(object) 返回一個對象的類型,等價於object.__class

原创 python importsystem

https://docs.python.org/3/reference/import.html#importsystem 導入模塊的三個方法: 1.import 關鍵字 2.importlib.import_module() 3.