How to take input in list in python?
A list is a data structure, or it can be considered a container that can be used to store multiple data at once. The list will be ordered and there will be a definite count of it. The elements are indexed according to a sequence and indexing is done with 0 as the first index.
e.g.,
a=int(input("Number of elements in the list:-")) n=list(map(int, input("elements of list:-").strip().split())) print(n)
We can take input of list using for loop also.
e.g.,
a=[] n=int(input("Number of elements in list:")) for i in range(0,n): l=int(input()) a.append(l) print(a)
To create a list you separate the elements with a comma and enclose them with a bracket”[]”.
e.g.,
a=["Python", "C++", "C", "Java"] print(a)
This is all about taking input in list in python.
Subscribe
Login
Please login to comment
0 Discussion