定义一个类:圆形,该类有半径,周长,面积等属性,将半径隐藏起来,将周长与面积开放
import math
class circle:
def __init__(self, rad):
self.__rad=rad
# self.perimeter=perimeter
# self.area=area
@property
def perimeter(self):
return self.__rad * math.pi * 2
@property
def area(self):
return math.pi * self.__rad**2
c=circle(10)
print(c.area)
print(c.perimeter)