Python Tutorial Python Advanced Python References Python Libraries

Python - List Length



The Python len() function can be used to find out the total number of elements in the list. Along with this, len() function returns the number of elements of any iterable. An iterable object can be any data structure like list, tuple, set, string and dictionary, etc.

Syntax

len(list)

Parameters

list Required. specify iterable like a list to find out total number of elements in it.

Return Value

Returns the total number of elements in the list.

Example:

In the example below, Python len() function is used on the list called MyList to find out the total number of elements in it.

MyList = [10, 20, 30, 40, 50, 60]

print(len(MyList))

The output of the above code will be:

6

❮ Python List Methods