Find the Length of a List in Python

Published on Oct 02, 2020

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. ?

Comments (0)