美文网首页编程C++\C\Python
Python运行报错:can only concatenate

Python运行报错:can only concatenate

作者: 浅陌离殇_ | 来源:发表于2020-05-07 17:35 被阅读0次

python的刷题使用中遇到了这个错误:can only concatenate str (not "int") to str
上网查过后发现是因为我没有做数据类型的转换,python并不能像java一样,在做拼接的时候自动把类型转换为string类型;
故而需要进行一个类型转换,譬如将print(1+"a")改为print(str(1)+"a")就可以了;
特此记录下,以免后续再犯

相关文章

网友评论

    本文标题:Python运行报错:can only concatenate

    本文链接:https://www.haomeiwen.com/subject/aoaaghtx.html