Python Language List Length of a list

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

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?