close

How do I convert user input into a list?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How do I convert user input into a list in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How do I convert user input into a list?

  1. How do I convert user input into a list?

    gtlamber is right. But you don't need actualy to do anyting as the string has most of the list interface (means that you can treat string as a list).

  2. convert user input into a list

    gtlamber is right. But you don't need actualy to do anyting as the string has most of the list interface (means that you can treat string as a list).

Method 1

Use the built-in list() function:

magicInput = input('Type here: ')
magicList = list(magicInput)
print(magicList)

Output

['p', 'y', 't', 'h', 'o', 'n', ' ', 'r', 'o', 'c', 'k', 's']

Method 2

gtlamber is right. But you don’t need actualy to do anyting as the string has most of the list interface (means that you can treat string as a list). You can do for instance:

print(magicInput[1])
print(magicInput[2:4])

Output:

'y'
'th'

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read