#?Enter?a?codeclass?Animal(object):????
def?__init__(self,age,name,location):????????
????self.__age?=?age????????
????self.__name?=?name????????
????self.__location?=?location
????
????#Defined?the?fuction?that?can?get?the?details????
????def?get_age(self):????????
????????return?self.__age????
????def?get_name(self):????????
????????return?self.__name????
????def?get_location(self):????????
????????return?self.__location????
????def?get_details(self):????????
????????print('name:{},age:{},location:{}'.format(self.get_name,self.get_age,self.get_location))
????
????
????#Defined?the?fuction?that?can?modify?the?instance????
????def?set_age(self,age):????????
????????self.__age?=?age????
????def?set_name(self,name):????????
????????self.__name?=?name????
????def?set_location(self,location):????????
????????self.__location?=?location???????
????
?dog?=?Animal(18,'Jack','Asia')
?print(dog.get_details)
2021-11-18
2021-09-28
方法 get_details(self) 中,self.get_name,self.get_amge, self.get_location調(diào)用是屬性,而并沒有定義這個(gè)屬性,所以打印出應(yīng)該是'name:,age:,location:'才對(duì)。如果調(diào)用方法,就是少了括號(hào)
2021-08-17
輸出后是> 不好意思 打錯(cuò)了