As Green Cloak Guy mentioned, input()
always returns a single string.
In Python 3.x, if you want multiple inputs you can use the .split()
method and a list comprehension:
input_list = [int(x) for x in input("Enter values for list: ").split()]
#Enter values for list: 1 2 3 4 5
input_list
Out[4]: [1, 2, 3, 4, 5]
Keep in mind this will only work for integer values, if you want the user to input float values as well, you can change int(x)
to float(x)
. Only caveat is that the integer values will also be cast to float values:
input_list = [float(x) for x in input("Enter values for list: ").split()]
#Enter values for list: 1 2 3.3 4 5
input_list
Out[8]: [1.0, 2.0, 3.3, 4.0, 5.0]
More on the .split()
method here
More on list comprehensions here