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(不在函数中)的方法,它可以工作,但由于某些原因它不能在函数中工作。
note = input("Whats up")
有人能给我解释一下吗?
试试这个:
notes =[] def newNote(notes): note = input("Whats up") notes.append(note) return notes inp = input("in or out? ") if (inp == "in"): newNote(notes)
input = input("in or out? ") 输入 用另一个名称替换变量名,它就可以工作了。
input = input("in or out? ")
线路问题 input = input("in or out? ") .
你重新定义了 input 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)