社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

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

SwagMoney 206 • 5 年前 • 1518 次点击  
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社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/57245
 
1518 次点击  
文章 [ 3 ]  |  最新文章 5 年前
Sultan Singh Atwal
Reply   •   1 楼
Sultan Singh Atwal    5 年前

试试这个:

notes =[]
def newNote(notes):
    note = input("Whats up")
    notes.append(note)
    return notes

inp = input("in or out? ")
if (inp == "in"):
    newNote(notes)

Lior Cohen
Reply   •   2 楼
Lior Cohen    5 年前

input = input("in or out? ") 输入 用另一个名称替换变量名,它就可以工作了。

Yurii Karabas
Reply   •   3 楼
Yurii Karabas    5 年前

线路问题 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)