1. 首页
  2. 数据库
  3. 其它
  4. Python特殊属性property原理及使用方法解析

Python特殊属性property原理及使用方法解析

上传者: 2021-02-23 18:13:09上传 PDF文件 49KB 热度 18次
1 什么是特性property property是一种特殊的属性,访问它时会执行一段功能(函数)然后返回值 import math class Circle: def __init__(self,radius): #圆的半径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(
用户评论