[英]TypeError 'str' object is not callable in Python
The command prompt says TypeError: 'str' object is not callable. 命令提示符显示TypeError:“ str”对象不可调用。 It highlights these two separate lines of code.
它突出显示了这两行代码。
height = float(input('Please enter your height input meters(decimals): '))
height = int(input('Please enter your height input inputches(whole number: '))
Now you see why you should never name a variable after a built-in. 现在你明白为什么你不应该命名内置后的变量。 ;)
;)
You said yourself that you made a variable named input
elsewhere in the code. 您自己说自己在代码的其他地方创建了一个名为
input
的变量。 Judging by your error, you must have done this before those two lines. 根据您的错误判断,您必须在这两行之前完成此操作。 Also, you must have made this variable hold a string.
另外,您必须使此变量包含一个字符串。
By doing this, you overshadowed the built-in input
. 通过这样做,您使内置
input
黯然失色。 This means that, when you get to those two lines, input
no longer exists as the built-in. 这意味着,当您到达这两行时,
input
不再作为内置input
存在。 Instead, it is a string. 相反,它是一个字符串。
Finally, placing (...)
after input
throws an error because you can't call a string like a function. 最后,在
input
之后放置(...)
会引发错误,因为您不能像函数一样调用字符串。
Summed up, you can fix the problem by simply picking a different name for that variable besides input
. 总结起来,您可以通过为
input
之外的变量选择一个不同的名称来解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.