A list is a data structure in Python and, like other classes, it has a header in its implementation. However, this header also includes the implementation of the method len()
which returns the length of the list.
len(obj)
The parameter may be a sequence (i.e., string, bytes, tuple, list, or range) or a collection (i.e., a dictionary or a set).
len()
returns the length of an object; the length is the same as the number of items in an object.
my_list = [1,2,3,4,5]len_my_list = len(my_list)print("The length of my_list is",len_my_list)
Free Resources