Built-in functions of list in python 5 examples

Built-in functions of list in python

Built-in functions of list in python

There is some built-in functions used in Python List.

#1 len()

#2 max()

#3 min()

#4 sum()

#5 sorted()

Let’s take one by one built-in functions of list in python with example.

#1 len()

len() function is used to calculate the length of the list.

sports = [ ‘Cricket’, ‘Hockey’, “Football’, ‘Tennis’, ‘Volleyball’ ]

len(sports)

Output

5

#2 max()

max() function is used to determine the maximum number in the list.

list = [ 2, 9, 7, 3, 6 ]
max(list)

Output

9

#3 min()

min() function is used to determine the minimum number in the list.

list = [ 2, 9, 7, 3, 6 ]
min(list)

Output

2

#4 sum()

sum() function is used to the addition of all elements in the list.

list = [ 2, 9, 7, 3, 6 ]
sum(list)

Output

27

#5 sorted()

The sorted() function is used to sort the list but it does not make any changes to the original list.

list = [ 2, 9, 7, 3, 6 ]
sorted( list )

Output

[ 2, 3, 6, 7, 9 ]

Now you have learned Built-in functions of list in python

 

Important Links: Informatics Practices

If you like my post please share it with your friends by simply clicking the below social media button, and Don’t forget to comment so we will update ourselves.

Share in a Single Click

Leave a Reply

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