Day_13_AM_Property_Decorator
class Person:
def __init__(self, name, wechat):
self.name = name
self.__wechat = wechat
# # getter 间接获取私有属性
# def get_wechat(self):
# return self.__wechat
#
# # setter 间接修改私有属性
# def set_wechat(self, new_wechat):
# self.__wechat = new_wechat
@property # 作用:让get函数可以当成属性来调用
def wechat(self):
return self.__wechat
@wechat.setter
def wechat(self, new_wechat):
self.__wechat = new_wechat
@property
def photo(self):
s = self.name + self.__wechat
return s
# 对象
p = Person('刘亦菲', '110',)
# print(p.get_wechat())
#
# p.set_wechat('119')
# print(p.get_wechat())
print(p.wechat)
p.wechat = '120'
print(p.wechat)
print(p.photo)