property属性

property属性就是负责把类中的一个方法当作属性进行使用,这样可以简化代码使用。

class Person(object):
	def __init__(self):
		self.__age = 0

	# 装饰器方式的property, 把age方法当作属性使用,表示当前获取属性时会执行下面修饰的方法
	@property
	def age(self):
		return self.__age

定义property属性有两种方式