-
兩個(gè)內(nèi)建函數(shù):
dir()
type()
查看全部 -
在python3.6時(shí)兩個(gè)定義類的方法輸出會(huì)是一樣了,在2.7的時(shí)候運(yùn)行顯示如視頻一樣!
查看全部 -
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
注釋的都是錯(cuò)誤的
__getattr__ 是獲取不到屬性的時(shí)候才會(huì)被調(diào)用的.
__getattribute__?每次都會(huì)被調(diào)用
查看全部 -
查看全部
-
平常不需要__ new__ 因?yàn)橥ǔJ抢^承了父類的(新式類均有繼承), 父類會(huì)創(chuàng)建類對象.
查看全部 -
def?__new__(cls): ????#?pass ????return?cls
__new__ 其實(shí)在 __init__ 之前創(chuàng)建一個(gè)對象, 且__ new__必須返回一個(gè)對象的,? __init__不需要返回.
查看全部 -
@property?裝飾的?method?調(diào)用的時(shí)候就不用()了. @classmethod?裝飾的方法,需要類名來調(diào)用.
查看全部 -
類的三個(gè)特點(diǎn)
封裝性,繼承性,多態(tài)性
查看全部 -
jietu
查看全部 -
()(,,,).name._age.__weight().__weight pPerson(,,) (p.name) (p._age) (p.__getweight__())???(p._Person__weight)??((p))????(p.)
查看全部 -
請輸入筆記內(nèi)容...
查看全部 -
設(shè)置對象屬性:
查詢對象屬性:
__getattr__:不是每次調(diào)用,查詢不到時(shí)調(diào)用
__getattribute:每次都調(diào)用
查看全部 -
比較運(yùn)算符:
__cmp__(self,other)、__eq__(self,other) 、__lt__(self,other) 、__gt__(self,other)
數(shù)字運(yùn)算符:
__add__(self,other) 、 __sub__(self,other)?? 、 __mul__(self,other)? 、? __div__(self,other)
邏輯運(yùn)算符:
__or__(self,other) 、? __and__(self,other)
查看全部 -
對象實(shí)例化的過程:
查看全部 -
Magic Method:方法名的前后有兩個(gè)下劃線
如:def? __innit__(self):
查看全部
舉報(bào)