Python中多个值的输入函数
a,b=int(input("Enter two numbers").split())
print(a+b)
我已经编写了此代码以在使用输入()函数输入时添加两个数字。 它给出了一个错误。 我知道我们可以使用MAP功能转换为INT,但是此方法呢? 这里的错误是什么? [图片描述了它给出的错误]
a,b=int(input("Enter two numbers").split())
print(a+b)
I have written this code to add two numbers while taking input using input() function.
It is giving an error.
I know we can convert to int using map function but how about this method?
What is the error here?
[The pic depicts th error which it gives]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
split
返回字符串列表,因此您需要在该列表中的每个项目上调用int
。在列表上调用int
是没有意义的。例如split
returns a list of strings, so you need to callint
on each of the items in that list. It doesn't make sense to callint
on a list. For example您可以尝试一下(使用
map
功能)。You could try this (Using
map
function).