报错 TypeError: can only concatenate str (not “int“) to str

错误代码:

money = 5000
print("你还有" + money + "元")

输出结果:

TypeError: can only concatenate str (not "int") to str

修改代码为:

money = 5000
print("你还有" + str(money) + "元")

输出结果:

你还有5000元

原因分析:
在print()中 " + "前后的值数据类型需要一致

你可能感兴趣的:(报错,python)