To take input in list from user in python; In this python article, we would share with you how to declare a list, input elements, append the elements in the list, and ultimately, print the list in python.
When you create this program in Python, you will need Python’s functions like, list.append() function, input() function, for loop with range() function.
Python Program to Take Input in List from User
Use the following steps to write a python program to take list as input and create a list from user input:
- First of all, declare a list in python.
- Take Input a limit of the list from the user.
- Use for loop to take a single input number from the user.
- Use list.append() to add elements in python list.
- Print the list using for loop.
# Python Program to input, append and print the list elements # declare a list myList =  # take number from user, how many element in list n = int (input ("How many element in list :- ")) # append element into list using list.append for i in range (n) : storeElement = int (input ("Enter an integer num :- ")) myList.append (storeElement) # print all elements print("Input list elements are: ") for i in range (n) : print(myList [i])
After executing a the program, the output will be:
How many element in list :- 4 Enter an integer num :- 1 Enter an integer num :- 2 Enter an integer num :- 3 Enter an integer num :- 4 Input list elements are: 1 2 3 4
Recommended Python List Programs
- Python Print List Elements in Different Way
- Python Add and Remove Elements From List
- Python: Add/Insert Element at Specified Index in List
- Python Program to Remove ith/Nth Occurrence of Given Word in List
- Python Program to Sort List in Ascending and Descending Order
- Python to Find the Differences of Two Lists
- Python to Find Minimum and Maximum Elements of List
- Python Programs to Split Even and Odd Numbers in Separate List
- Python Program to Create Two Lists with First Half and Second Half Elements of Given List
- Python Program to Swap Two Elements in a List
- Python Program to Reverse List
- How To Select Random Item From A List In Python
- Python Program to Find Second Largest Number in List