Skip to course content
Free course

Python Foundations / Module 8 / Why Arrays Differ from Lists

Module 8 lesson

Why Arrays Differ from Lists

Unit ID: M08-U00 Estimated active time: 18-25 minutes

A Python list can hold mixed objects. That flexibility is useful, but numerical work often needs one predictable type and operations across every value. A NumPy array stores values in a regular structure and makes its shape and data type visible.

Predict before running:

import numpy as np

minutes_list = [30, 45, 60]
minutes_array = np.array(minutes_list, dtype=np.int64)
print(minutes_list * 2)
print(minutes_array * 2)

The list repeats its items. The array multiplies each value. Neither behaviour is universally better; the correct structure depends on the task.

Use an array when the values are meaningfully numeric, have a regular shape, and need selection, transformation, or aggregation. Keep labels and irregular records in dictionaries or pandas tables.

Practice: write one reason the supplied study-minutes data suits a two-dimensional array and one reason learner names should stay outside that numeric array.