Python inheritance returns attribute error

后端 未结 3 493
死守一世寂寞
死守一世寂寞 2021-01-06 12:52

Just starting out Python, i\'m a fan of Derek Banas and have been following a tutorial and I\'m stuck with a bit of code.

class Dog(Animal):
    __owner = \"         


        
3条回答
  •  情话喂你
    2021-01-06 13:20

    Change your function code

    from

    def toString(self):
            return "{} is {} cm tall and {} kilograms and say {} and the owner is {}".format(
            self.__name,
            self.__height,
            self.__weight,
            self.__sound,
            self.__owner)
    

    to

    def toString(self):
            return "{} is {} cm tall and {} kilograms and say {} and the owner is {}".format(
            self.get_name(),
            self.get_height(),
            self.get_weight(),
            self.get_sound(),
            self.get_owner())
    

提交回复
热议问题