為什么分數不能作為key
>>> d={
...???? 95:'Adam',
...???? 85:'Bart'
... }
>>> for key in d:
...???? print key + ':',d[key]
...
Traceback (most recent call last):
? File "<stdin>", line 2, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'
拋開題目的name:score格式不談,是分數不能為key,還是我個人操作錯誤
2017-08-18
d={
??? 95:'Adam',
??? 85:'Bart'
??? }
for key in d:
??? print key,':',d[key]
講+換成,試試? 報錯的意思是int 和str類型不能用+連接
2017-11-03
key是整型,‘:’是字符串,不是同一種類型不能用+,要用逗號。