I have a parent class:
class Animal(object):
animalFoods = {'Elephant': ['Grass', 'Trees'], 'Turtle': 'Fish'}
def animal_food(self):
foods = Animal.animalFoods[self.__class__.__name__]
for food in foods:
return food
Then I have a subclass:
class Elephant(Animal):
pass
I create an object:
Dumbo = Elephant()
And try to print out its food choice:
>>> print(Dumbo.animal_food())
Grass
I expect it to print out
Grass
Trees
I see how it is working by finding the key in the animalFoods
dictionary, but I am not sure why it is not returning both values in the value list.
Pointers towards additional reading are appreciated over just providing a quick and dirty answer, as this is my first time working with dictionaries beyond single values.