__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')