TypeError: can only concatenate str (not “int“) to str
生活随笔
收集整理的這篇文章主要介紹了
TypeError: can only concatenate str (not “int“) to str
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
出現(xiàn)問題原因如下
報錯的地方告訴我了print 的地方報錯了
類型不一樣引起的問題
處理這個問題有2種方法
方法1: 轉(zhuǎn)換類型
pi = 3
print("當前的p=" + str(pi))
方法2 使用字符串格式化
pi = 3
print("當前的p= %s" % pi) # %s 是格式化字符串
在不知道類型的情況下建議使用字符串格式化
總結(jié)
以上是生活随笔為你收集整理的TypeError: can only concatenate str (not “int“) to str的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 电动车是“48V20A”的电池一般能跑多
- 下一篇: 你爱生死我来娶下一句是什么啊?