Arrays — the array Module in Python
Python's built-in list is flexible but stores items as general Python objects, which uses more memory than necessary when every item is the same simple type, like all integers. The array module provides a typed array that only holds one specified type, packed more compactly — a middle ground between a plain list and a full numeric library like NumPy.
import array
Brings in the array type, part of the standard library.
Create one with a typecode
array.array(typecode, values) — the typecode specifies the kind of number stored, like 'i' for signed integers.
Every item must match that type
Otherwise Python raises a TypeError.
Most list operations still work
Indexing, slicing, and appending all behave the same way as on a list.
NumPy is the usual next step
For serious numeric work, most Python code reaches for NumPy arrays, which add fast vectorized math on top of this same typed-storage idea.
import array numbers = array.array('i', [1, 2, 3, 4])print(numbers)print(numbers[0]) numbers.append(5)print(numbers)Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in Python yourself — building beats watching.