#源码:
class Person:
def init(self,name,age):
print('gouzao')
self.__name=name
self.__age=age
@property
def age(self):
print('thisis get')
return self.__age
@age.setter
def age(self,value):
print('jinlaileme')
if 0<age<150:
print('if ')
self.__age=value
def display(self):
print('person({s} {age})'.format(s=self.__name,age=self.__age))
def __str__(self):
return 'person({s} {age})'.format(s=self.__name,age=self.__age)
def __repr__(self):
return str(self)
p=Person('gsdg',32)
print(p.age)
p.age=21
print(p.age)
print(p)
#打印信息:
gouzao
thisis get
32
21
person(gsdg 32)