PI = 3.14
class Circ(object):
def __init__(self):
pass
def __call__(self, r):
return r * r * PI
c = Circ()
print c(2) #12.56
把对象当作函数来用,相当于重载括号运算符
PI = 3.14
class Circ(object):
def __init__(self):
pass
def __call__(self, r):
return r * r * PI
c = Circ()
print c(2) #12.56
把对象当作函数来用,相当于重载括号运算符
转载于:https://www.cnblogs.com/bjdxy/archive/2012/11/12/2766281.html