+ 2

Why is the result of the code in the description showing me "Woof!" in a different line and then "Dogs always None" ??

class Animal: def __init__(self, name, color): self.name = name self.color = color class Cat(Animal): def purr(self): print("Purr...") class Dog(Animal): def bark(self): print("Woof!") fido = Dog("Fido", "brown") print("Dogs always",fido.bark())

3rd Apr 2017, 6:18 PM
--_--
--_-- - avatar
4 Réponses
+ 12
No, it doesn't return it to the calling line. It prints Woof in the bark method without returning a value.
3rd Apr 2017, 6:57 PM
Tashi N
Tashi N - avatar
+ 11
Your bark method doesn't return a value, that's the reason why None is printed.
3rd Apr 2017, 6:51 PM
Tashi N
Tashi N - avatar
+ 2
but it returns the value "Woof!" first.
3rd Apr 2017, 6:56 PM
--_--
--_-- - avatar
+ 1
okay thnx
3rd Apr 2017, 7:12 PM
--_--
--_-- - avatar