why this code shows NONE in output in last line? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

why this code shows NONE in output in last line?

the code is in python... class Animal: def __init__(self, name, color): self.color = color self.name = name class cat(Animal): def purr(self): print("purrrrrr.......") class dog(Animal): def bark(self): print("bark bark bark.....") class rabbit(Animal): def jump(): print("ping pong.....") x = dog("pony", "brown") y = cat("kitty", "white") z = rabbit("jaggy" , "brown") print(x.color, ' = ', x.name) print(y.color, ' = ', y.name) print(z.color, ' = ', z.name) print(x.bark())

14th Dec 2019, 3:11 PM
Avinash
Avinash - avatar
1 Answer
+ 5
The `bark` method of the `dog` class does not return anything (no return statement there). When a function or method doesn't return anything you'll get None if you try to use the return value (because none is returned literally).
14th Dec 2019, 3:21 PM
Ipang