List Methods in Python with Examples

List Methods in Python

Python provides several built-in functions to work with lists. Some of the commonly used list methods are explained below:


a) len() – Returns the Number of Elements in a List

The len() function returns the total number of elements present in a list.

Example:

numbers = [10, 20, 30, 40, 50]
print(len(numbers))

Output: 5


b) min() – Returns the Smallest Element in the List

The min() function returns the minimum value from the list. All elements must be of the same data type.

Example:

values = [88, 75, 93, 67, 85]
print(min(values))

Output: 67


c) max() – Returns the Largest Element in the List

The max() function returns the highest value from the list.

Example:

marks = [45, 87, 92, 56, 78]
print(max(marks))

Output: 92


d) sum() – Returns the Sum of All Elements in the List

The sum() function calculates the total of all numeric elements in a list.

Example:

expenses = [100, 250, 175, 300]
print(sum(expenses))

Output: 825


Summary Table

MethodDescriptionExampleOutput
len()Returns number of elements in the listlen([1, 2, 3])3
min()Returns smallest element in the listmin([4, 1, 9])1
max()Returns largest element in the listmax([4, 1, 9])9
sum()Returns sum of all list elementssum([10, 20, 30])60

Leave a Reply

Your email address will not be published. Required fields are marked *