Sep-19-2017, 02:49 AM
this can be simplified even more with a list comprehension:
pets = [["Garfield", "cat", 4], ["Dog", "dog", 7.5], ["Porkey", "pig", 61], ["Stoned", "rock", 0.230]] for pet in pets: name = pet[0] species = pet[1] weight = pet[2] print('Name: {}, species: {}, weight: {}'.format(name, species, weight))results:
Output:Name: Garfield, species: cat, weight: 4
Name: Dog, species: dog, weight: 7.5
Name: Porkey, species: pig, weight: 61
Name: Stoned, species: rock, weight: 0.23