python面向对象__call__
call
任何对象后面加(),触发执行。
class People:
def __init__(self,name):
self.name = name
def __call__(self, *args, **kwargs):
print("call")
class Student(People):
def walk(self):
print("walking....")
p=People("egon")
print(callable(People))
print(callable(p))
s =Student("allen")
s()
执行结果
True
True
call