class foo(object):
def __init__(self, x):
self.x = x
def __call__(self, x): # 改变实例
self.x = x
e = foo(1)
print(e.x) # 1
e(2)
print(e.x) # 2
参考:
https://www.jianshu.com/p/e1d95c4e1697?utm_source=oschina-app
class foo(object):
def __init__(self, x):
self.x = x
def __call__(self, x): # 改变实例
self.x = x
e = foo(1)
print(e.x) # 1
e(2)
print(e.x) # 2
参考:
https://www.jianshu.com/p/e1d95c4e1697?utm_source=oschina-app