Length of Array in Python

Learn via video course
FREE
View all courses
Python Course for Beginners With Certification: Mastering the Essentials
Python Course for Beginners With Certification: Mastering the Essentials
by Rahul Janghu
1000
4.90
Start Learning
Python Course for Beginners With Certification: Mastering the Essentials
Python Course for Beginners With Certification: Mastering the Essentials
by Rahul Janghu
1000
4.90
Start Learning
Topics Covered

Overview

We have learned that arrays are a collection of objects, and these collections can have any number of objects: zero, one, ten, and so on. The number of objects in the array is called its length. We need to know the length of an array to perform various operations like iterating over the array, checking whether an element belongs to the array and reading/updating elements in the array.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Introduction

Let us take an array as follows:

How many elements are in the array? The answer is 5. Hence the length of the array is also 5.

If we were to give indexes to each element in the array as follows:

introduction link

Essentially, the length of an array is the highest index position + 1.

Array Length in Python using the len() method

Python has a len() method to find out the length of an array. The syntax is as follows:

Example

Output

Finding the Length of a Python NumPy Array

Numpy is a library compatible with Python for operating complex mathematical operations on multi-dimensional arrays. We use numpy for mathematical operations on arrays. Here is how we can find the length of an array in Python using numpy:

Example

Output

Conclusion

  • Length of an array is the number of elements present in the array.
  • In python, the length of an array is the highest index of an array + 1.
  • We can use Python's len() function to find the length of an array.
  • For a Numpy array also, we can use the len() function to find the array's length in Python.

Boost your career prospects with Scaler Topics Python certification course. Get started now!

Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more