Write a python program to read a number of elements in the list
To count the no of elements in the list we can use in-built length method or iterative over the list.
Method 1:-
Code:-
l=[1,2,3,4,5,6]
print("No of elements in the list are:-",len(l))
Output:-
No of elements in the list are:- 6
Method 2:-
Code:-
l=[1,2,3,4,5,6]
count=0
#iterate over the list
for i in l:
count+=1
print("No of elements in the list are:-",count)
Output:-
No of elements in the list are:- 6
0 Comments