In this lesson we will learn about Python list len method. This len
method will return the number of elements in the list.
Python list len Method
Python list len method is an effective way to get the number of elements in a list. The len
method can also be used for getting number of elements in Dictionary and Tuple.
Syntax
The syntax for len method is given below:
len( myList )
- myList – that specific List of which you want to get the number of elements.
This method will return the number of elements.
Examples
Here are some examples of Python list len method:
myList1 = ['apple', 'banana','lemon', 'orange'] myList2 = ['a','b','c','d','e','f'] print " Length of myList1 is : ", len( myList1 ) print " Length of myList2 is : ", len( myList2 )
If you run this script then the output will look like this:
Length of myList1 is : 4 Length of myList2 is : 6
You can also use the len() method for getting number of elements in Dictionary, Tuple, even String.
The post Python List len Method – Python len() appeared first on JS Tricks.