I'm trying to make it so that when a Boxer object is created there is no need to specify the breed as it is automatically set to Boxer
class Dog:
def __init__(self, name, age, breed):
# instance attributes
self.name = name
self.age = age
self.breed = breed
class Boxer(Dog):
super().__init__().breed = "Boxer"
def speak(self,sound = 'woof'):
print(f'{self.name} says {noise}')
hettie = Boxer('Hettie',5)
hettie.speak()
At the moment when I run this code I get this error:
RuntimeError: super(): no arguments
I tried initially to put the super()
line inside the __init__()
method but then I had an issue with not enough arguments when I called Boxer
def __init__(self):
super().breed = "boxer"
but if I added arguments I still had issues
def __init__(self,breed):
super().breed = "boxer"
question from:
https://stackoverflow.com/questions/65849044/changing-instance-attributes-of-a-parent-class-from-a-child-class 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…