【发布时间】:2014-10-19 01:08:48
【问题描述】:
inventory = {
'gold' : 500,
'sack' : ['rock', 'copper wire'],
'weapons rack' : ['pistol', 'MP-5', 'grenade'],
'ammo pouch' : ['Pistol ammo', 'MP-5 ammo'],
}
print "You have " + inventory['gold'][0] + " coins!"
我收到错误消息:
line 8, in <module>
print "You have " + inventory['gold'] + " coins!"
TypeError: 'int' object has no attribute '__getitem__'
为什么控制台不打印出"You have 500 gold coins!"
【问题讨论】:
标签: python list dictionary printing