Python 3 – List len() Method
Python 3 – List len() Method
Description
len() method returns the number of elements in a list.
Syntax
Following is the syntax of the len() method –
len(list)
Parameters
list – This is the list whose number of elements is to be counted.
Return Value
This method returns the number of elements in the list.
Example
The following example demonstrates the use of the len() method.
#!/usr/bin/python3
list1 = ['physics', 'chemistry', 'maths']
list2 = list(range(5)) #Create a list of numbers between 0 and 4
print (len(list2))
Result
When running the above program, it will produce the following result –
3
5