代码
ralph = {'type': 'cat','owner': 'mark'}
lucy = {'type': 'cat','owner': 'carrie'}
pets = [ralph, lucy]
for pet in pets:
print(str(pet))
owner = pet['owner']
print('pet type: ' + pet['type'] + '\n' + 'owner: ' + owner.title())
提供输出:
{'type': 'cat', 'owner': 'mark'}
pet type: cat
owner: Mark
{'type': 'cat', 'owner': 'carrie'}
pet type: cat
owner: Carrie
我试图打印每只宠物的名字(拉尔夫和露西)
翻翻过去那场雪
慕哥6287543
随时随地看视频慕课网APP
相关分类