Saturday, November 16, 2024
Google search engine
HomeLanguagesPython Accept List as a input From User

Python Accept List as a input From User

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

  1. Python Print List Elements in Different Way
  2. Python Add and Remove Elements From List
  3. Python: Add/Insert Element at Specified Index in List
  4. Python Program to Remove ith/Nth Occurrence of Given Word in List
  5. Python Program to Sort List in Ascending and Descending Order
  6. Python to Find the Differences of Two Lists
  7. Python to Find Minimum and Maximum Elements of List
  8. Python Programs to Split Even and Odd Numbers in Separate List
  9. Python Program to Create Two Lists with First Half and Second Half Elements of Given List
  10. Python Program to Swap Two Elements in a List
  11. Python Program to Reverse List
  12. How To Select Random Item From A List In Python
  13. Python Program to Find Second Largest Number in List
RELATED ARTICLES

Most Popular

Recent Comments