Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

length
list
python

How to get the length of a list in Python

Educative Answers Team

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.

svg viewer

Syntax

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; t​he length is the same as the number of items in an object.

Code

my_list = [1,2,3,4,5]
len_my_list = len(my_list)
print("The length of my_list is",len_my_list)

RELATED TAGS

length
list
python
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring