Hello so im new on python, i want to know how to do multiple string input on list. I already try to append the input to the list, but it doesn't give me expected output. Here is the source code:
test=[]
input1=input("Enter multiple strings: ")
splitinput1=input1.split()
for x in range(len(splitinput1)):
test.append(splitinput1)
print(test)
print(len(test))
And the output is not what i expected:
Enter multiple strings: A B C
[['A', 'B', 'C'], ['A', 'B', 'C'], ['A', 'B', 'C']]
3
However, when i change to print(splitinput1), it give me expected output:
Enter multiple strings: A B C
['A', 'B', 'C']
3
So how to make the output like print(splitinput1) while use print(test) and whats missing on my code? Thankyou.
forloop. Just dotest = input("Enter multiple strings: ").split().forloops, the code you want isfor x in splitinput1: test.append(x). You don't want to append all ofsplitinput1totestthree times, you want to append each of the three items individually. (Thisforloop is also the same astest.extend(splitinput1).)