【发布时间】:2011-02-18 20:59:44
【问题描述】:
我在尝试获取一个整数并在其前面加上“b”并将其转换为字符串时收到此错误:
File "program.py", line 19, in getname
name = "b" + num
TypeError: Can't convert 'int' object to str implicitly
这和这个函数有关:
num = random.randint(1,25)
name = "b" + num
【问题讨论】:
-
This SO answer 解释了为什么 Python 不像 Javascript 那样将
+的 RHS 转换为str。这让我有点惊讶,但这个答案很好地解释了这一点。
标签: python python-3.x