【发布时间】:2011-10-27 09:46:20
【问题描述】:
为什么这会给我一个错误?
>>> variable = str(21)
Traceback (most recent call last):
File "<pyshell#101>", line 1, in <module>
variable = str(21)
TypeError: 'str' object is not callable
【问题讨论】:
-
您是否将变量命名为“str”?
-
您是否定义了另一个字符串变量并将其分配给变量
str?因为这样做你最终会隐藏内置函数str()例如:str = 'test'; print(str(124))。 -
投错了票。我们大多数人在学习时都使用过内置函数。看看有多少带有
list = [...]的代码示例。我更新了这个问题的标题。
标签: python python-3.x shadowing