I'm new to python and I'm trying to scan multiple numbers separated by spaces (let's assume '1 2 3' as an example) in a single line and add it to a list of int. I did it by using:
#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()]
Apparently it works, since when I type in '1 2 3' and do a print(array)
the output is:
[1, 2, 3]
But I want to print it in a single line without the brackets, and with a space in between the numbers, like this:
1 2 3
I've tried doing:
for i in array:
print(array[i], end=" ")
But I get an error:
2 3 Traceback (most recent call last):
print(array[i], end=" ")
IndexError: list index out of range
How can I print the list of ints (assuming my first two lines of code are right) in a single line, and without the brackets and commas?
question from:
https://stackoverflow.com/questions/37625208/printing-an-int-list-in-a-single-line-python3 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…