Help! A Mystery of Inheritance, Classes, Subclass - getting a None Error message. | Sololearn: Learn to code for FREE!
0

Help! A Mystery of Inheritance, Classes, Subclass - getting a None Error message.

Hi, so I wrote the following code... class Animal: def noise(self): print("noise") class Dog(Animal): def noise(self): print("woof") class Hog(Animal): def noise(self): print("snort") print(Animal().noise(), "xx ", Dog().noise(),"xx ", Hog().noise()) And the output I get is: noise woof snort None xx None xx None Then when I delete the line of code with the print method, ie class Animal: def noise(self): print("noise") class Dog(Animal): def noise(self): print("woof") class Hog(Animal): def noise(self): print("snort") #print(Animal().noise(), "xx ", Dog().noise(),"xx ", Hog().noise()) Then the output is.. .. there's not output. I do not understand what's going on here In the first code version, I expected the output would be "noise xx bark xx snort". A) Why was the output noise bark snort on separate lines and without the xx? B) Why did None xx None xx None print? C) Why when in the second version and I got rid of the print function, was there no output? I expected it to be noise bark snort on separate lines Thanks!

1st May 2019, 11:56 AM
Josie The Ritalin Dog
Josie The Ritalin Dog - avatar
0 Réponse