+ 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())
1 Respuesta
+ 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).