Computer >> Computer tutorials >  >> Programming >> Python

How do we get size of a list in Python?


Python's built in function len() returns number of elements in a sequence including list object.

>>> L1=[1,2,3,4,5]
>>> len(L1)
5

The built-in function len() implements the __len__() method defined for all sequence type classes including list class. It also returns size.

>>> L1.__len__()
5