friend這個參數(shù)也沒用,python怎么就知道Alice是friend了呢?
python怎么知道p('alice')應(yīng)該往my?friend?is?的format上安,而不是往my?name?is的那個format上安?就是后面也沒寫一下p('alice')跟friend這個參數(shù)有聯(lián)系,它怎么就自動套上了呢?
p('Alice')?#?==>?用函數(shù)的方式調(diào)用Person類的實(shí)例p
def?__call__(self,?friend): ????????print('My?name?is?{}...'.format(self.name)) ????????print('My?friend?is?{}...'.format(friend))
2020-10-26
2021-11-23
簡單來說
? ? ? ? ? ? ? ? ??