-
兩個內建函數:
dir()
type()
查看全部 -
在python3.6時兩個定義類的方法輸出會是一樣了,在2.7的時候運行顯示如視頻一樣!
查看全部 -
def?__setattr__(self,?key,?value): ????#?setattr(self,?key,?value) ????self.__dict__[key]?=?value def?__getattribute__(self,?item): ????#?return?getattr(self,?item)??#??RuntimeError:?maximum?recursion?depth?exceeded ????#?return?self.__dict__[item] ????return?super(Magic,?self).__getattribute__(item) def?__getattr__(self,?item): ????return?"no?attr?%s"?%?item
注釋的都是錯誤的
__getattr__ 是獲取不到屬性的時候才會被調用的.
__getattribute__?每次都會被調用
查看全部 -
查看全部
-
平常不需要__ new__ 因為通常是繼承了父類的(新式類均有繼承), 父類會創建類對象.
查看全部 -
def?__new__(cls): ????#?pass ????return?cls
__new__ 其實在 __init__ 之前創建一個對象, 且__ new__必須返回一個對象的,? __init__不需要返回.
查看全部 -
@property?裝飾的?method?調用的時候就不用()了. @classmethod?裝飾的方法,需要類名來調用.
查看全部 -
類的三個特點
封裝性,繼承性,多態性
查看全部 -
jietu
查看全部 -
()(,,,).name._age.__weight().__weight pPerson(,,) (p.name) (p._age) (p.__getweight__())???(p._Person__weight)??((p))????(p.)
查看全部 -
請輸入筆記內容...
查看全部 -
設置對象屬性:
查詢對象屬性:
__getattr__:不是每次調用,查詢不到時調用
__getattribute:每次都調用
查看全部 -
比較運算符:
__cmp__(self,other)、__eq__(self,other) 、__lt__(self,other) 、__gt__(self,other)
數字運算符:
__add__(self,other) 、 __sub__(self,other)?? 、 __mul__(self,other)? 、? __div__(self,other)
邏輯運算符:
__or__(self,other) 、? __and__(self,other)
查看全部 -
對象實例化的過程:
查看全部 -
Magic Method:方法名的前后有兩個下劃線
如:def? __innit__(self):
查看全部
舉報