Python Get Length of List (Size of List in Python)
![Python Get Length of List](https://s3.us-west-2.amazonaws.com/static.elearning.wsldp.com/images/python/python-list-length.webp)
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.
![python get length of list](https://s3.us-west-2.amazonaws.com/static.elearning.wsldp.com/images/python/python-get-length-of-list.webp)
If the list is empty, the len()
function will return 0.