'''lecture_31_veggie_extend.py `SweetPotato` inherits from `Veggie`. The `SweetPotato` extends `Veggie` with `isYam` method and `isAYam` instance variable in __init__ Oliver W. Layton CS 151: Computational Thinking: Visual Media Fall 2020 ''' class Veggie: def __init__(self, name): self.name = name print('In Veggie constructor') def describeYourself(self): print('I am a', self.name, 'and I am SAVORY') class SweetPotato(Veggie): def __init__(self, name, isAYam): super().__init__(name) self.isAYam = isAYam # def describeYourself(self): # print('I am a', self.name, 'and I am SWEET') def isYam(self): return self.isAYam if __name__ == '__main__': pot = Veggie('Potato') sweetPot = SweetPotato('Sweet potato', True) print('Is this sweet potato a yam?', sweetPot.isYam()) # print('Is this potato a yam?', pot.isYam()) # side note: __init__ method actually is in object symbol table # Not typically done # pot.__init__('New potato') # behaves like ordinary method # pot2 = pot.__init__('New potato') # behaves like ordinary method # print(pot2) # pot.describeYourself()