e Learning

Python Get Length of List (Size of List in Python)

If you want to get the length or size of a Python list (array), use the built-in len() function.

The len() function returns the number of elements in the list, the syntax of the len() function is as follows:

len(list)

For example, consider the following example:

countries = ['Italy', 'Brazil', 'Spain', 'Sweden']

print(len(countries))

In this example, we have a list called countries which contain four elements. So the len() function should return 4.

get length of list

If the list is empty, the len() function will return 0.