__call__ 函數,將類實例當作函數使用,弱化了函數和對象的區別。函數
class Person(object): def __init__(self, name, gender): self.name = name self.gender = gender def __call__(self, friend): print('I am %s' % self.name) print('My friend is %s' % friend) p = Person('Bob', 'male') p('Tim')