(continued from previous page print( __dict__{'ispet''no''animal''lion' print(jungle __dict__""{'__doc__''__doc__'list of animal and pet information \ animal string\ ispet string\ ''__weakref__''__module__''__main__''__dict__''__init__'"" print(jungle __doc__"""list of animal and pet information animal string ispet string "" standard boilerplate to set 'mainas starting function if __name__=='__main__'main( __setattr__ and __getattr__ method __setattr__ is executedwhenever we set the value of an attribute __setattr__ can be useful for validating the input-types before assigning them to attributes as shown in line of listing please read the comments of listing for better understanding similarly__getattr__ is invoked whenever we try to access the value of an attributewhich is not in the dictionary listing __setattr__ and __getattr__ setattr py class studentiddef __init__(selfidnameage " ")self id id self firstname name self age age all the init parameters need to be specified in 'setattrdef __setattr__(selfnamevalue)if(name ="id")setting id if isinstance(valueintand value self __dict__["id"value elseprint("id must be positive integer"raise typeerror("id must be positive integer"elif (name ="firstname")setting firstname self __dict__["firstname"value elsesetting age self __dict__[namevalue getattr is executedwhen attribute is not found in dictionary def __getattr__(selfname)raise attributeerror("attribute does not exist" def main() studentid( "meher"print( ids firstnames age meher #uncomment below line to see the "typeerrorgenerated by 'setattr(continues on next page object oriented programming