“str"对象不可调用 - 注意:不要将特殊函数用作变量 [英] 'str' object is not callable - CAUTION: DO NO USE SPECIAL FUNCTIONS AS VARIABLES
问题描述
如果您定义了预定义类型,例如:str = 5
然后该预定义的原始功能将更改为新功能.经验教训:不要给预定义或属于特殊函数的变量命名.在这里列出:这里
在将其标记为重复之前,请查看此python代码和结果
X=5print("X 值为:"+str(X))
<块引用>
回溯(最近一次调用最后一次):文件",第 1 行,在print("X 值为:"+str(X))类型错误:str"对象不可调用*
据我所知, str 应该在这里工作,因为我只是在这里打印变量的值.有什么线索吗?
问题是str函数一定是重载了.
输入:
X=5print("X 值为:"+str(X))
输出:X值为:5
输入:
X=5str = "98897"print("X 值为:"+str(X))
输出:TypeError Traceback(最近一次调用最后一次)在 ()----> 1 print("X 值为:"+str(X))
TypeError: 'str' 对象不可调用
EDIT: If you define a predefined type such as:
str = 5
then the original functionality of that predefined will change to a new one. Lesson Learnt: Do not give variables names that are predefined or belong to special functions. List here: Here
Before you mark it as duplicate, please see this python code and results
X=5
print("X value is:"+str(X))
Traceback (most recent call last): File "", line 1, in print("X value is:"+str(X)) TypeError: 'str' object is not callable*
As far as I know, str should work here because I am simply printing the value of variable here. Any clues?
The problem is str function must have been overloaded.
Input:
X=5
print("X value is:"+str(X))
Output: X value is:5
Input:
X=5
str = "98897"
print("X value is:"+str(X))
Output: TypeError Traceback (most recent call last) in () ----> 1 print("X value is:"+str(X))
TypeError: 'str' object is not callable
这篇关于“str"对象不可调用 - 注意:不要将特殊函数用作变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!