Python len() function

Published February 16, 2022

You will need to know the number of items contained in a data structure whenever programming. To do this, you should use the Python len() function. The len() function in Python is a built-in function that returns the length of the specified object. For instance, it can return the number of the items in the specified list.

Syntax
 The following is the  simple syntax of the len() function.
 

len(iterable_object)


The len() function takes a single argument, the iterable_object, of which the length needs to be calculated. The len() method returns the number of items in the iterable object, implying that each value in the object is allocated an index value.
Let's look at an example to see how the len() method works in more detail.


Example
In this example, we are going to use the len() function to identify the  number of items in my_list

my_list = ["Python", "C#", "PHP", "Vue", "JavaScript", "Kotlin"]
print(len(my_list))

 

Output

6

 

Download Source code

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

248 Views