I am trying to inherit methods from one a base class to another class, specifically the __str__
method, where I only need to change it a little by adding a note.
Something like this.
class Person:
def __init__(self, name=None):
self.name = name
def __str__(self):
return ' Name: ' + str(self.name)
And my second class.
class AnnotatedPerson(Person):
def __init__(self, name=None, note=None):
super().__init__(name=None)
self.note = note
def __str__(self):
return ' Name: ' + str(self.name) + 'Note:' + str(self.note)
However this is not working, when printing print(AnnotatedPerson.__str__())
on an object I only get the part note
and the name
part in the __str__
method is set to None
for objects that do have a value.
What is my mistake?