python报错:TypeError: can only concatenate str (not "int") to str 电脑版发表于:2022/5/19 11:39 ``` number1 = input("请输入加数1:\n") number2 = input("请输入加数2:\n") result = int(number1)+int(number2) print("两数之和为:"+result) ``` 上面的代码执行会报错: tn>python中,print函数不能同时识别2种数据类型。直接print("两数之和为:"+result)会报错,无法把字符串和int类型相加,不像c#那样会自动转换,所以需要手动转化一下。 输出修改成如下即可: ``` print("两数之和为:"+str(result)) ``` ![](https://img.tnblog.net/arcimg/aojiancc2/1239c7efefcf47ce869df8dd0d05f4c5.png)