我希望在打印john.gender时打印出性别值。我该怎么做。我需要在代码中编辑什么
class Human:
def __init__(self,name,gender,tribe):
self.name = name
self.gender ={
0:"Male",
1:"Female"
}
self.tribe ={
0:"Germanic",
1:"Egyptian",
2:"Norse"
}
def saying(self):
if self.tribe == 0:
print(self.name, "I am from the great Germanic tribes")
john = Human("John",0,0)
print(john.gender)
你不能在
__init__()
中设置约翰的性别Human().gender
将始终是{0: 'Male', 1: 'Female'}
如果你想把它摆成你所拥有的样子,你会想要更接近以下的东西:
在上面的例子中,我们将
self.gender
设置为由genders
dict中的键命名的值相关问题 更多 >
编程相关推荐