MyInternships.in

Python Data Structures

Python Arrays

Python does not have a dedicated array type built into the core language the way C does — instead you choose between lists, the array module, and NumPy depending on your needs.


Lists Are Python’s Default "Array"

For most beginner and everyday tasks, a regular list already behaves like a dynamic array: it grows automatically and can be indexed, sliced, and looped over. Most Python code never needs anything more specialised.

A list used as an array
Python
scores = [85, 92, 78, 90]
scores.append(88)
print(scores[2])   # 78

The array Module

The built-in array module gives you a true fixed-type array. Every element must be the same numeric type, declared with a one-letter typecode, which saves memory compared to a list of the same size.

Using the array module
Python
import array

nums = array.array("i", [1, 2, 3, 4])  # 'i' = signed int
nums.append(5)
print(nums)         # array('i', [1, 2, 3, 4, 5])
print(nums[0])      # 1

Common Typecodes

TypecodeC TypePython Type
'i'signed intint
'f'floatfloat
'd'doublefloat
'u'wchar_tUnicode character

NumPy Arrays

For serious numerical work — data analysis, machine learning, image processing — the third-party NumPy library’s ndarray is the standard choice. It supports fast vectorised math, multiple dimensions, and a huge ecosystem of tools.

A NumPy array (requires pip install numpy)
Python
import numpy as np

grid = np.array([[1, 2], [3, 4]])
print(grid.shape)   # (2, 2)
print(grid * 2)     # element-wise multiplication
Installing NumPy
Terminal
pip install numpy

Which One Should You Use?

  • List — default choice for everyday Python code, mixed types, small to medium data.
  • array module — large collections of one numeric type, when you need lower memory use and have no extra dependencies.
  • NumPy array — numeric/scientific computing, matrices, and any project already using data-analysis libraries.
ℹ️

When people say "Python array" in casual conversation they usually mean a list — the array module and NumPy are more specialised tools you reach for as your needs grow.

Related Python Topics

Keep learning with these closely related lessons.

Ready to use your Python skills?

Find Python, data science and software internships and fresher jobs across India.

Browse Python Internships