在python中如何在一行中接受多个输入
我正在为此使用列表压缩:在python中如何在一行中接受多个输入,python,Python,我正在为此使用列表压缩: x = [i for i in int(raw_input("Enter Input:")).split(",")] Enter Input : 1 2 3 4 5 但它抛出了一个错误: Traceback (most recent call last): File "python", line 1, in <module> ValueError: invalid literal for int() with base 10: '1 2 3 4 5' 回
x = [i for i in int(raw_input("Enter Input:")).split(",")]
Enter Input : 1 2 3 4 5
但它抛出了一个错误:
Traceback (most recent call last):
File "python", line 1, in <module>
ValueError: invalid literal for int() with base 10: '1 2 3 4 5'
回溯(最近一次呼叫最后一次):
文件“python”,第1行,在
ValueError:基数为10的int()的文本无效:“1 2 3 4 5”
有人能帮我整理一下吗。不要用
,
,用空格分开。…split()
。此外,split将为您提供一个值数组。您必须迭代每个元素并键入cast toint
。我刚刚尝试过,仍然无法工作。您可以上传代码[int(I)for I in input().split()]吗?默认情况下,这将由spacethnx@Rednivrug拆分
x = [int(i) for i in raw_input("Enter Input:").split(" ")]