Find Size of A List In Python

Find List Size In Python

This is a quick tutorial on finding the size of a list in python. All you need to do is to pass the list variable as an argument to the inbuilt len() function.

Consider the following python code in which I’ve created a list containing 5 different integers, so the length of this python list should be 5.

aList = [1,2,3,4,5]

Now, we’ll simply pass the variable aList as a parameter to the function len() which will return the length of the list.

length = len(aList)

Example.

aList = [1,2,3,4,5]
length = len(aList)
print(length)

Output.

Python List Length Using Len() Function

You can also pass a list directly into the len() function as shown in the following example.

length = len(['A','B','C'])
print(length)

List As Argument Python Length Function

The function of len() function is not just limited to lists but it also works for finding out the length of almost every other data type in python.

Leave a Reply

Your email address will not be published. Required fields are marked *