当前位置: 代码迷 >> 综合 >> python运行报错TypeError: cannot concatenate 'str' and 'int' objects
  详细解决方案

python运行报错TypeError: cannot concatenate 'str' and 'int' objects

热度:15   发布时间:2023-12-22 15:58:33.0

dict运行报错

d = {
    'Adam': 95,
    'Lisa': 85,
    'Bart': 59
}
for key in d:
    print key+":"+d[key]

TypeError: cannot concatenate 'str' and 'int' objects

字符类型和数字类型不能用+拼接,而是用","

d = {
    'Adam': 95,
    'Lisa': 85,
    'Bart': 59
}
for key in d:
    print key+":",d[key]

  相关解决方案