Python provides an inbuilt function len() which is used to find the size or length of a list.
Size or length of a list means the total number of elements in it.

len() syntax
len() function accepts the list whose size you want to calculate as argument and returns its length as shown below.

len(list)

len() function can be used with other structures as well such as a tuple, set or a string.
In case of string, len() returns the number of characters in the string.
len() example
Example of len() function to find the length of a list is given below.

numbers = []
numbers.append(1)
numbers.append(2)
numbers.append(3)
print('Length of list is:',len(numbers))

This code example creates an empty list and then adds elements using list append() method. After adding elements, it prints the length of list with len() function.
Output is

Length of list is: 3

Besides len() function, there are other methods to find the length of list.
Hit the clap below
if the article was helpful.

0
Liked the article ? Spread the word...

Leave a Reply