List methods are discussed in this article.
1. len() :- This function returns the length of list.
List = [1, 2, 3, 1, 2, 1, 2, 3, 2, 1] print(len(List)) Output: 10
2. min() :- This function returns the minimum element of list.
List = [2.3, 4.445, 3, 5.33, 1.054, 2.5] print(min(List)) Output: 1.054
3. max() :- This function returns the maximum element of list.
List = [2.3, 4.445, 3, 5.33, 1.054, 2.5] print(max(List)) Output: 5.33
Python3
lis = [2, 1, 3, 5, 4]
print ("The length of list is : ", end="")
print (len(lis))
print ("The minimum element of list is : ", end="")
print (min(lis))
print ("The maximum element of list is : ", end="")
print (max(lis))
|
Output
The length of list is : 5
The minimum element of list is : 1
The maximum element of list is : 5
Output:
The length of list is : 5
The minimum element of list is : 1
The maximum element of list is : 5
4. index(ele, beg, end) :- This function returns the index of first occurrence of element after beg and before end.
List = [1, 2, 3, 1, 2, 1, 2, 3, 2, 1] print(List.index(2)) Output: 1
5. count() :- This function counts the number of occurrences of elements in list.
List = [1, 2, 3, 1, 2, 1, 2, 3, 2, 1] print(List.count(1)) Output: 4
Python3
lis = [2, 1, 3, 5, 4, 3]
print ("The first occurrence of 3 after 3rd position is : ", end="")
print (lis.index(3, 3, 6))
print ("The number of occurrences of 3 is : ", end="")
print (lis.count(3))
|
Output
The first occurrence of 3 after 3rd position is : 5
The number of occurrences of 3 is : 2
Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills and become a part of the hottest trend in the 21st century.
Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.
Last Updated :
03 Aug, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...