list input in python

Python Program to get list size n and n elements of list, then print the elements.

Sample Input 1:

5 5 7 9 3 1

Sample Output 1:

5 7 9 3 1

Try your Solution

Strongly recommended to Solve it on your own, Don't directly go to the solution given below.

#write your code here

Program or Solution

l=list(map(int,input("Enter array elements:").split(" ")))
for i in l:


Program Explanation

To get list of numbers separated by space, use split(" ") method.

Split() method splits the numbers as separate elements.

By default this methods are considered as string, since input() method returns string. Use map() function to convert all elements as integer and store it in list.