我是python新手,我try 在一行中扫描多个由空格分隔的数字(假设"1 2 3"为例),并将其添加到int列表中.我使用:
#gets the string
string = input('Input numbers: ')
#converts the string into an array of int, excluding the whitespaces
array = [int(s) for s in string.split()]
显然,它是有效的,因为当我输入'1 2 3'并输入print(array)
时,输出是:
[1, 2, 3]
但我想把它打印成一行,不带括号,在数字之间留一个空格,就像这样:
1 2 3
我试过做:
for i in array:
打印(数组[i],end="")
但我有一个错误:
2.3回溯(最近一次通话最后一次):
打印(数组[i],end="")
索引器:列表索引超出范围
如何在一行中打印int列表(假设我的前两行代码是正确的),而不使用括号和逗号?