class Animal:
def eat(self):
print("eats well")
def sleep(self):
print("sleeps well")
class Dog(Animal):
def init(self,breed,color):
self.breed= breed
self.color= color
Canela=Dog("chihuahua","brown")
print("This dog is a",Canela.breed,"and its color is",Canela.color)
#untill there ir works but how can I add the information from the parent class, If I do
print("This dog is a",Canela.breed,"and its color is",Canela.color,"and",Canela.eat()) it appears It eats well at the top and none next to the sentence. How can I write it well?
>Solution :
that’s is because your eat function print to the stdout and does not return a string.
you need to change your eat function to be:
def eat(self):
return "eats well"