Python字符串连接数字

新学Python,很简单问题折腾我两天。

我就是想把String连接上字符串。杂就搞不定。不是说要转换成字符串: str(num)吗?报错依然。

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


这让从事PHP开发的我一脸蒙蔽。这也能难到我。好了不BB了。上解决方法。


其实很简单,先把字符转换成 bytes(num),然后再连接就行了


item = bytes(item)
        insertVal += s + "'" + item + "'"

也是没谁了!

猜你喜欢

转载自blog.csdn.net/hotlinhao/article/details/79385769
今日推荐