How to Input a List in Python using For Loop Last Updated : 21 Feb, 2025 Comments Improve Suggest changes Like Article Like Report Using a for loop to take list input is a simple and common method. It allows users to enter multiple values one by one, storing them in a list. This approach is flexible and works well when the number of inputs is known in advance.Let’s start with a basic way to input a list using a for loop in Python. Python n = int(input("Number of elements: ")) a = [] # Use a for loop to take input from user for i in range(n): # Collect input for each element val = input() a.append(val) print(a) Output:Number of elements: 41234['1', '2', '3', '4']Explanation: We are first prompting the user to specify how many elements to enter. Then, the for loop runs n times each time taking input and appending it to the list a.Note: We can modify this code to input integers, floats or other types by using appropriate type casting.Using List ComprehensionList comprehension offers a concise way to take multiple inputs in a single line and store them in a list. This approach is more efficient and reduces the need for explicit append() calls, resulting in a more "Pythonic" approach. Python n = int(input("number of elements: ")) a = [input() for i in range(n)] print(a) Output:number of elements: 3456['4', '5', '6']Explanation: This approach creates a list a directly by iterating over a range using list comprehension. Comment More infoAdvertise with us Next Article How to Input a List in Python using For Loop A anuragtriarna Follow Improve Article Tags : Python Python Programs python-list Python list-programs Practice Tags : pythonpython-list Similar Reads How to Initialize a Dictionary in Python Using For Loop When you want to create a dictionary with the initial key-value pairs or when you should transform an existing iterable, such as the list into it. You use string for loop initialization. In this article, we will see the initialization procedure of a dictionary using a for loop. Initialize Python Dic 3 min read How to Take List of Tuples as Input in Python? Lists of tuples are useful data structures in Python and commonly used when you need to group related elements together while maintaining immutability within each group. We may need to take input for a list of tuples from the user. This article will explore different methods to take a list of tuples 3 min read How to Take Array Input in Python Using NumPy NumPy is a powerful library in Python used for numerical computing. It provides an efficient way to work with arrays making operations on large datasets faster and easier. To take input for arrays in NumPy, you can use numpy.array. Taking Array Input Using numpy.array()The most simple way to create 3 min read Get User Input in Loop using Python In Python, for and while loops are used to iterate over a sequence of elements or to execute a block of code repeatedly. When it comes to user input, these loops can be used to prompt the user for input and process the input based on certain conditions. In this article, we will explore how to use fo 3 min read How to skip Iterations in For Loop - Python Loops are generally used to repeat the tasks. Sometimes, we may want to skip certain steps in the loop. We can do this easily with the continue statement. This article explains how to skip iterations in a for loop.In a for loop, you can use continue to skip a specific iteration when a condition is t 2 min read Like