python----特性001

时间:2023-04-02 17:54:26

特性001:python 中特性的一个例子:

#!/usr/local/python3.5/bin/python3

class Person(object):
def __init__(self,name):
self.name=name
def get_name(self):
print('this is get name')
return self.name
def set_name(self,name):
print('this is set name')
self.name=name
def del_name(self):
print('this is del name')
del self.name
Name = property(get_name,set_name,del_name,'name property ...') if __name__=="__main__":
jlx=Person('Jianglexing')
print(jlx.Name)