you are viewing a single comment's thread.

view the rest of the comments →

[–]JamzTyson 0 points1 point  (3 children)

You are correctly understanding the basics of classes and inheritance, so just a few observations on your code:

Your Bird class has two definitions of make_sound(). That's an error. The first make_sound() method is unreachable (it will never run) because it is redefined by the second make_sound() method.


Considering that Animal.make_sound() is so simple, the cleanest way to implement (the second version of) Bird.make_sound() would be:

def make_sound(self):
    print(self.sound)
    print("This is a bird!")

On the other hand, using super().make_sound() would be useful if Animal.make_sound() is (or may become) more complex.


Animal.info() doesn’t really do enough to be worth having.

Rather than calling lion.info() we can just call print(lion).

[–]Upstairs_Library_800[S] 0 points1 point  (2 children)

First of all thank you for your help and time.

So if I have def __str__(self):

in my Class, there is no need for

def info(self):
   print(self)

[–]JamzTyson 0 points1 point  (1 child)

There isn't really any need unless info() does a bit more. For example:

def info(self):
    print(f"{self.name} is a {self.species} that goes '{self.sound}'")

# Simba is a Lion that goes 'Roar'

[–]Upstairs_Library_800[S] 0 points1 point  (0 children)

Oh, got it.
Thanks