Find Size of a List in Python

Last updated by Dipen Dadhaniya on Sep 25, 2025 at 03:43 PM
| Reading Time: 3 minutes

In Python, List is one of the most frequently used and versatile data types. Knowing how to harness the power of a list’s versatile nature can be useful on innumerable occasions. If you’re a software engineer relatively new to Python programming, this article can help you move towards your Python learning goals.

In this article, we’ll learn:

  • What Is a List in Python?
  • The len() Function in Python
  • Finding the Size of a List Using len() Function
  • Finding the Size of a List Using for Loop
  • FAQs

What Is a List in Python?

A list in Python is a collection data type used to store several values using a single variable. The values in the list may or may not be of the same type. However, it is usually used to store values of the same type, which represent some collection. It can also store duplicate values. A list is ordered and changeable and is represented by writing values separated by commas, stored within square brackets as shown below.

listOfOdd=[1, 3, 5, 7, 9]

listOfChar=[‘a’, ‘b’, ‘c’, ‘d’]

listOfMix=[‘a’, ‘b’, 1, 3]

The len() Function in Python

len() is a built-in function in Python that returns the length of an object like a list, string, dictionary, set, tuple, etc. The len() function takes one argument: an object which may be a sequence or a collection, and returns an integer, which is the number of items in the object, i.e., its size. len() performs this operation in O(1) time.

 

Syntax:

len(object)

 

Example:

listEx = [1, 2, 3, ‘a’,’b’,’c’]

stringEx=’InterviewKickstart’

setEx={0,2,4,6,8}

tupleEx=(0,’Zero’,1,’One’)

dictionaryEx={‘Zero’: 0, ‘One’:1, ‘Two’:2}

print(len(listEx))

print(len(stringEx))

print(len(setEx))

print(len(tupleEx))

print(len(dictionaryEx))

Output:

6

18

5

4

3

Finding the Size of a List Using len() Function

The most commonly used method of finding the size of a list is using the len() function. The built-in class list also has a method __len__(), which also returns the size/number of items in the list.

The len() function actually works by calling the object’s __len__() method. Since attributes in the format __xyz__ often are more complex than we realize, their direct use isn’t encouraged. Hence we prefer the len() method for finding the size of a list. Let us look at both of these methods through an example.

Example:

Code

#adding some elements in an empty list

listEx = []

listEx.append(1)

listEx.append(3)

listEx.append(5)

listEx.append(‘seven’)

listEx.append(‘nine’)

#getting the size of the list after adding multiple elements

print(len(listEx))

print(listEx.__len__())

Output

5

5

Finding The Size of a List Using for Loop

We can also find the size of a list by simply using a for loop, creating a count variable, iterating through all the items in the list, and incrementing the value of count by one in each iteration.

Since this method isn’t very pythonic, we again prefer the len() function for finding the size of a list. We can make use of a for loop to find the length of each element in a list that only stores objects while using the len() function. Let us see how we can use this method through an example.

Example:

Code

listEx = [1, 2, 3, ‘a’,’b’,’c’,’Interview’, ‘Kickstart’]

count = 0

for item in listEx:

count = count + 1

 

print(‘The size of the list is: ‘, count)

# When elements in a list are also objects, we can also use a for loop to calculate the length of each element in the list,

# while we use the len() function to find the length of the

# list

listEx2=[‘Interview’, ‘Kickstart’]

for item in listEx2:

print(item, ‘ is of size ‘, len(item))

 

print (‘Length of the list  = ‘, len(listEx2))

Output

The size of the list is:  8

Interview  is of size  9

Kickstart  is of size  9

Length of the list  =  2

FAQs

Question 1: Can we use the len() function in a for loop to find the size of string elements in a list that also contains items that are not objects (like int, char, etc.)?

Example:

listEx = [‘a’,’b’,’c’, 1 ,’Interview’, ‘Kickstart’]

Answer: No. len() takes an object as its argument, and we’ll get a type error since int, char, etc., are not objects.

Question 2: Can we use the len() function in a for loop to find the size of string elements in a list that also contains items that are objects but of different types (like a dictionary, tuple, etc.)

Example:

listEx = [{‘a’:1,’b’:1,’c’:1},’Interview’, ‘Kickstart’]

Answer: Yes. If the list contains elements of different data types, but all are objects that are sequences or collections, we can use the len() function to find the size of each element.

Are You Ready to Nail Your Next Coding Interview?

Whether you’re a Coding Engineer gunning for Software Developer or Software Engineer roles, or you’re targeting management positions at top companies, IK offers courses specifically designed for your needs to help you with your technical interview preparation!

If you’re looking for guidance and help with getting started, sign up for our free webinar. As pioneers in the field of technical interview prep, we have trained thousands of Software Engineers to crack the most challenging coding interviews and land jobs at their dream companies, such as Google, Facebook, Apple, Netflix, Amazon, and more!

Sign up now!

————

Article contributed by Tanya Shrivastava

Last updated on: September 25, 2025
Register for our webinar

Uplevel your career with AI/ML/GenAI

Loading_icon
Loading...
1 Enter details
2 Select webinar slot
By sharing your contact details, you agree to our privacy policy.

Select a Date

Time slots

Time Zone:

Strange Tier-1 Neural “Power Patterns” Used By 20,013 FAANG Engineers To Ace Big Tech Interviews

100% Free — No credit card needed.

Register for our webinar

Uplevel your career with AI/ML/GenAI

Loading_icon
Loading...
1 Enter details
2 Select webinar slot
By sharing your contact details, you agree to our privacy policy.

Select a Date

Time slots

Time Zone:

IK courses Recommended

Land high-paying DE jobs by enrolling in the most comprehensive DE Interview Prep Course taught by FAANG+ engineers.

Fast filling course!

Ace the toughest backend interviews with this focused & structured Backend Interview Prep course taught by FAANG+ engineers.

Elevate your engineering career with this interview prep program designed for software engineers with less than 3 years of experience.

Ready to Enroll?

Get your enrollment process started by registering for a Pre-enrollment Webinar with one of our Founders.

Next webinar starts in

00
DAYS
:
00
HR
:
00
MINS
:
00
SEC

Register for our webinar

How to Nail your next Technical Interview

Loading_icon
Loading...
1 Enter details
2 Select slot
By sharing your contact details, you agree to our privacy policy.

Select a Date

Time slots

Time Zone:

Almost there...
Share your details for a personalised FAANG career consultation!
Your preferred slot for consultation * Required
Get your Resume reviewed * Max size: 4MB
Only the top 2% make it—get your resume FAANG-ready!

Registration completed!

🗓️ Friday, 18th April, 6 PM

Your Webinar slot

Mornings, 8-10 AM

Our Program Advisor will call you at this time

Register for our webinar

Transform Your Tech Career with AI Excellence

Transform Your Tech Career with AI Excellence

Join 25,000+ tech professionals who’ve accelerated their careers with cutting-edge AI skills

25,000+ Professionals Trained

₹23 LPA Average Hike 60% Average Hike

600+ MAANG+ Instructors

Webinar Slot Blocked

Interview Kickstart Logo

Register for our webinar

Transform your tech career

Transform your tech career

Learn about hiring processes, interview strategies. Find the best course for you.

Loading_icon
Loading...
*Invalid Phone Number

Used to send reminder for webinar

By sharing your contact details, you agree to our privacy policy.
Choose a slot

Time Zone: Asia/Kolkata

Choose a slot

Time Zone: Asia/Kolkata

Build AI/ML Skills & Interview Readiness to Become a Top 1% Tech Pro

Hands-on AI/ML learning + interview prep to help you win

Switch to ML: Become an ML-powered Tech Pro

Explore your personalized path to AI/ML/Gen AI success

Your preferred slot for consultation * Required
Get your Resume reviewed * Max size: 4MB
Only the top 2% make it—get your resume FAANG-ready!
Registration completed!
🗓️ Friday, 18th April, 6 PM
Your Webinar slot
Mornings, 8-10 AM
Our Program Advisor will call you at this time

Get tech interview-ready to navigate a tough job market

Best suitable for: Software Professionals with 5+ years of exprerience
Register for our FREE Webinar

Next webinar starts in

00
DAYS
:
00
HR
:
00
MINS
:
00
SEC

Your PDF Is One Step Away!

The 11 Neural “Power Patterns” For Solving Any FAANG Interview Problem 12.5X Faster Than 99.8% OF Applicants

The 2 “Magic Questions” That Reveal Whether You’re Good Enough To Receive A Lucrative Big Tech Offer

The “Instant Income Multiplier” That 2-3X’s Your Current Tech Salary