Find the Length of a List in Python

Last modified on January 16, 2021 27 sec read

We're available to do freelance project. Take a look at our services!

A list in Python is used to store the sequence of various types of data. It is one of the most commonly used data types in Python. This article shows how to find the length of a list.

Table of Contents

  1. Using len() Function
  2. Using Loop

Using len() Function

The syntax of the len() function:


Let’s have a look at an example:

list_capital = ['Dhaka', 'London', 'Tokyo']

length = len(list_capital)

print("The length of the list is: {0}" . format(length))

Using Loop

We can do the same thing using for loop.

list_capital = ['Dhaka', 'London', 'Tokyo']

count = 0
for capital in list_capital:
    count = count + 1

print("The length of the list is: {0}" . format(count))

We should always prefer using the len() function.

That’s it. Thanks for reading. 🙂

Monthly Newsletter

One email a month, packed with the latest tutorials, delivered straight to your inbox.
We'll never send any spam or promotional emails.

Hey, I'm Md Obydullah. I build open-source projects and write on Laravel, Linux server, modern JavaScript and more on web development.


Leave a Reply

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