Python Language List Length of a list

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9


Use len() to get the one-dimensional length of a list.

len(['one', 'two'])  # returns 2

len(['one', [2, 3], 'four'])  # returns 3, not 4

len() also works on strings, dictionaries, and other data structures similar to lists.

Note that len() is a built-in function, not a method of a list object.

Also note that the cost of len() is O(1), meaning it will take the same amount of time to get the length of a list regardless of its length.

Got any Python Language Question?