Saturday, March 24, 2018

List len() Method


List len( ) Method


The len() method returns the number of elements in the list.

Syntax
len(list)

Parameters
list - This is a list for which, number of elements are to be counted.

Return Value
This method returns the number of elements in the list.

Example
#!/usr/bin/python3

list1 = ['physics', 'chemistry', 'maths']
print (len(list1))
list2=list(range(5)) #creates list of numbers between 0-4
print (len(list2))

When we run above program, it produces following result-
3
5




<<< Built-in List Functions                   Index                    max( ) Method >>>