我需要我的代码帮助,我想在display_details中显示该句子

问题描述 投票:0回答:1
    class Pet:
        def __init__(self, name, animal_type, age):
            self.__name = name
            self.__animal_type = animal_type
            self.__age = age

        def set_name(self, name):
            self.__name = name

        def set_animal_type(self, animal_type):
            self.__animal_type = animal_type

        def set_age(self, age):
            self.__age = age

        def get_name(self):
            return self.__name

        def get_animal_type(self):
            return self.__animal_type

        def get_age(self):
            return self.__age

        def display_details(self):
            return "Pet {} is a {}, and it is {} years old".format(self.__name, self.__animal_type, 
self.__age)

//问题出在这里^

name = input("Enter pet name:")
    animal_type = input("Enter pet type:")
    age = int(input("Enter age of pet:"))
    Pet(name, animal_type, age)

// im试图显示display_details下的句子,但我在输出中看不到它// lllllllllllllllllllllllllllllllllllllllllllllllllllll

python python-3.7
1个回答
1
投票
您是否创建了Pet类的实例?即:
© www.soinside.com 2019 - 2024. All rights reserved.