标签:fun TE attribute sed known getting 封装 class fine
class Person(): def __init__(self): self.__age = 0 def set_age(self, age): if age < 0 or age > 200: self.__age = 0 else: self.__age = age def get_age(self): return self.__age a = property(get_age, set_age) # def __init__(self, fget=None, fset=None, fdel=None, doc=None): # known special case of property.__init__ """ property(fget=None, fset=None, fdel=None, doc=None) -> property attribute fget is a function to be used for getting an attribute value, and likewise fset is a function for setting, and fdel a function for del‘ing, an attribute. Typical use is to define a managed attribute x: """ p = Person() p.a = 999 print(p.a)
标签:fun TE attribute sed known getting 封装 class fine
原文地址:https://www.cnblogs.com/wf-skylark/p/9157156.html