调用属性不用要加()
import math
class Circle:
def __init__(self, radius):
self.radius = radius
@property
def area(self):
return math.pi*self.radius**2
@property
def perimeter(self):
return 2*math.pi*self.radius
c = Circle(4.0)
print(c.radius)#而不是c.radius()
print(c.area)
print(c.perimeter)