Python错误[TypeError:'str'对象不可调用]在使用input()函数时出现

问题描述 投票:-1回答:3
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(不是在函数中)尝试过该行,它可以工作,但是由于某种原因,它在函数内不起作用。

有人可以向我解释吗?

python input callable
3个回答
1
投票

[C0行的问题。

您将input = input("in or out? ")函数重新定义为input的结果,所以现在input("in or out? ")是字符串。

解决方案是简单地将input结果变量更改为其他变量:

input("in or out? ")

0
投票

notes =[] def newNote(notes): note = input("Whats up") notes.append(note) return notes choice = input("in or out? ") if (choice == "in"): newNote(notes) 覆盖了内置的input函数。用其他名称替换变量名称,它将起作用。


0
投票

尝试一下:

input = input("in or out? ")

您已使用关键字“输入”来命名变量。除非要覆盖语言的内置功能,否则切勿使用关键字来定义函数或变量。

© www.soinside.com 2019 - 2024. All rights reserved.