How to take the list as input in Python | Example code

  • by

Use an input() function with split() function to take list as input in Python. Using a split() function will split an input string by space.

Example take the list as input in Python

Simple example code input() function to accept the list elements from a user in the format of a string separated by space. And The split() method splits a string into a list.

input_string = input('Enter separated by space: ')

user_list = input_string.split()

# print list
print('list: ', user_list)

Output:

How to take the list as input in Python

Do comment if you have any doubts or suggestions on this Python List input code.

Note: IDE: PyCharm 2021.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.