"""
使用已有的方法定义访问器/修改器
版本: v1.0
日期: 2019.03.27
作者: Catherine
python版本: 3.7
"""
class Car(object):
def __init__(self, brand):
self.set_brand(brand)
def get_brand(self):
return self._brand
def set_brand(self, brand):
self._brand = brand + '1'
def __str__(self):
return 'Car: [品牌=%s]' % self._brand
# 用已有的修改器和访问器定义属性
brand = property(get_brand, set_brand)
if __name__ == '__main__':
car = Car('JEEP')
print(car)
print(Car.brand)
print(Car.brand.fget)
print(Car.brand.fset)