Length of Array in Python

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
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
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:

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!