![](/img/trans.png)
[英]TypeError: 'str' object is not callable when using input() in PyDev for Eclipse
[英]Python Error [TypeError: 'str' object is not callable] comes up when using input() funtion
notes =[]
def newNote(notes):
note = input("Whats up")
notes.append(note)
return notes
input = input("in or out? ")
if (input == "in"):
newNote(notes)
note = input("Whats up")
是有问题的行,我认为它没有任何问题。 我已经通过 instelf (不在函数中)尝试了这条线,它可以工作,但由于某种原因,它在 function 内不起作用。
谁能给我解释一下?
line input = input("in or out? ")
的问题。
您将input
function 重新定义为input("in or out? ")
的结果,所以现在input
是一个字符串。
解决方案是简单地将input("in or out? ")
结果变量更改为另一个:
notes =[]
def newNote(notes):
note = input("Whats up")
notes.append(note)
return notes
choice = input("in or out? ")
if (choice == "in"):
newNote(notes)
input = input("in or out? ")
覆盖内置输入function。 用不同的名称替换变量名称,它将起作用。
尝试这个:
notes =[]
def newNote(notes):
note = input("Whats up")
notes.append(note)
return notes
inp = input("in or out? ")
if (inp == "in"):
newNote(notes)
您已使用关键字“输入”来命名变量。 除非你想覆盖语言的内置功能,否则你不应该使用关键字来定义函数或变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.