classes and object-oriented programming class foo(object)def _init_ (self,name)self _name name @property def name(self)return self _name @name setter def name(self,value)if not isinstance(value,str)raise typeerror("must be string!"self _name value @name deleter def name(self)raise typeerror("can' delete name" foo("guido" name name "montyf name del name calls name(get function calls setter name( ,"monty"calls setter name( , -typeerror calls deleter name( -typeerror in this examplethe attribute name is first defined as read-only property using the @property decorator and associated method the @name setter and @name deleter decorators that follow are associating additional methods with the set and deletion operations on the name attribute the names of these methods must exactly match the name of the original property in these methodsnotice that the actual value of the name is stored in an attribute _name the name of the stored attribute does not have to follow any conventionbut it has to be different than the property in order to distinguish it from the name of the property itself in older codeyou will often see properties defined using the property(getf=nonesetf=nonedelf=nonedoc=nonefunction with set of uniquely named methods for carrying out each operation for exampleclass foo(object)def getname(self)return self _name def setname(self,value)if not isinstance(value,str)raise typeerror("must be string!"self _name value def delname(self)raise typeerror("can' delete name"name property(getname,setname,delnamethis older approach is still supportedbut the decorator version tends to lead to classes that are little more polished for exampleif you use decoratorsthe getsetand delete functions aren' also visible as methods descriptors with propertiesaccess to an attribute is controlled by series of user-defined getsetand delete functions this sort of attribute control can be further generalized through the use of descriptor object descriptor is simply an object that represents the value of an attribute by implementing one or more of the special methods _get_ () _set_ ()and _delete_ ()it can hook into the attribute access mechanism and can customize those operations here is an examplef lib fl ff