Tuesday 17 September 2019

Built-in Functions for Python Lists

Built-in Functions for Python Lists



len( ) function with List


len ( ) finds the number of items or elements in a list. Following code will return the length of the list - insurance. 


>>> insurance = ['sbi', 'icici', 'hdfc', 'hsbc'] 
>>> print(len(insurance))
4

min() and max() functions with Lists


Mininum and Maximum value can be identified using min() and max() function from the lists as shown below:

>>> list1 = [1, 2, 5, 10, 8] 
>>> print(min(list1))
1

>>> print(max(list1))
10

No comments:

Post a Comment