Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Input multiple string in list – python

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

You have slight error in your code. Do this:

test=[]
input1=input("Enter multiple strings: ")
splitinput1=input1.split()
for x in splitinput1:
   test.append(x)
print(test)
print(len(test))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading