如何连接str和int对象?

如何连接str和int对象?

如果我试图做以下几件事:

things = 5print("You have " + things + " things.")

我在Python3.x中得到了以下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>TypeError: must be str, not int

..Python 2.x中也有类似的错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>TypeError: cannot concatenate 'str' and 'int' objects

我怎样才能解决这个问题?


侃侃尔雅
浏览 926回答 3
3回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python