New and currently learning about classes and OOP in Python I try to get the following simple part of the code to run I am doing but I can not understand why I am getting an error Please see the code given below:
class animal (object): für = true dff real_animal (self) : If fur: print "real animals" and: print "fake animal" class dog (animal): für = true def __init __ (self, not ): Self.name = name Rover = dog ( "Rover") Rover .real_animal ()
I get an error stating fur. By my understanding, classes can inherit classes. Therefore, since there is a rover - an example of class dog, which is a class animal. Should not I be able to run the functions of Base Class Angel on the rover? I basically want to fur dogs and therefore are real animals.
Thanks for helping a newbie.
You have at least two mistakes:
-
You need to refer to the variable variable as
self.fur
, as it is not a local variable, but a variable on the example / square -
In the
dog
category, you call the variableis_furf
, but in the original class it is just calledfür
.
No comments:
Post a Comment