class Foo(object):
def __init__(self,name):
self.name = name
def __call__(self, *args, **kwargs):
print(kwargs)
obj=Foo("chen")
obj(age = 10)
实现了call方法就可以使用对象调用方法了
class Foo(object):
def __init__(self,name):
self.name = name
def __call__(self, *args, **kwargs):
print(kwargs)
obj=Foo("chen")
obj(age = 10)
实现了call方法就可以使用对象调用方法了
本文标题:__call__方法和__init__
本文链接:https://www.haomeiwen.com/subject/cxqknxtx.html
网友评论