# PersonProp.py # value 'Bob' # variable fname # Constructor Attribute def __init__(self,fname) # Class Attribute cls.fname # Class Property using getters,setters,deleters # Decorators # @staticmethod -> constructor() # @classmethod -> class # @property -> getters, setters and deleters # Managed attributes allowing for a higher level of validation, computation and access class PersonProp: # Initialize 2 self.attrs def __init__(self, fname, lname): self.fname = fname # None by the deleter self.lname = lname # None by the deleter @property # Assigns method as a property of the class, and this will allow us to use getters,setters and deleters to manage the values in memory def fullname(self): # @fullname decorator for the fullname return f"{self.fname} {self.lname}" @fullname.setter def fullname(self, name): firstname, lastname = name.split() self.fname = firstname self.lname = lastname @fullname.deleter def fullname(self): print("Deleting name...") self.fname = None self.lname = None # Output person1 = PersonProp('Bob','Smith') # Create the instance object using the constructor print(person1.fullname) # Bob Smith using the @property 'getter' # Now, lets pass to the class a new person 'Jane Doe' person1.fullname = 'Jane Doe' # set fname and lname using the setter print(person1.fname) # Jane print(person1.lname) # Doe # delete the values using the deleter del person1.fullname print(person1.fname) # None print(person1.lname) # None