社区所有版块导航
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
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

Sultan Singh Atwal

Sultan Singh Atwal 最近创建的主题
Sultan Singh Atwal 最近回复了
5 年前
回复了 Sultan Singh Atwal 创建的主题 » 使用input()函数时出现Python错误[TypeError:'str'对象不可调用]

试试这个:

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

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

5 年前
回复了 Sultan Singh Atwal 创建的主题 » 如何在python中将input[by input()]值作为参数传递?

你可以试试这个:

def add(num1,num2):
    return num1 * num2

num 1 = int(input('Enter number1: '))
num2 = int(input('Enter number2: '))

print(add(num1,num2))

input函数将输入存储为字符串,因此代码中发生的情况是您正在输入两个整数,但它们存储为字符串。两个字符串不能相乘。您只需使用int()函数将输入字符串转换为整数。如果要乘浮点数,可以使用float()函数代替int()函数。在将字符串传递给函数后,还可以将其转换为整数或浮点数。像这样的:

def add(num1,num2):
    return int(num1) * int(num2)

num1=input('Enter number1: ')
num2=input('Enter number2: ')

print(add(num1,num2))