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