liveBook · Manning

Array

As explained in Python Workout: 50 ten-minute exercises

An array is an indexed, ordered collection of elements arranged in one or more dimensions, with elements accessed by position.

When Python code needs indexed, array-like storage, a list is usually the practical choice. Unlike an array, a list can grow and can hold values without a fixed element type. section 3.5

Arrays have fixed length and type. Python lists are implemented with arrays of pointers and reserve extra space, so appending is usually convenient but can eventually trigger reallocation and pointer movement. section 3.5

Choose among these representations according to the task:

  • Use lists or tuples for most ordinary Python array-like work. section 3.5
  • Use the standard-library array type or NumPy arrays when a genuine typed array is appropriate. section 3.5

Observe list growth

Measure length and memory size while appending values. The reported size stays constant across several appends, then jumps when reserved capacity runs out.

How Python Workout: 50 ten-minute exercises covers it

How deep it goes
Distinguishes array constraints from list behavior and explains hidden resizing, but stops short of detailed allocation algorithms.
Examples
Uses append-growth measurements showing stable sizes followed by memory-allocation jumps.
What you can do after
Evaluate array-like choices and understand why Python lists usually replace fixed-size arrays.
How it connects
Connects arrays with lists, tuples, the standard-library array type, and NumPy arrays.

Also explained in

Compare how 40 books explain array →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Python Workout: 50 ten-minute exercises. The section links point to the parts of the book it draws on.