array.array keeps values of one C type and provides sequence operations. It can be more compact than a list of integers when the problem is simple and its available types are enough.
Practical example
from array import array
samples = array("h", [120, -20, 350])
samples.append(90)
raw = samples.tobytes()
restored = array("h")
restored.frombytes(raw)
print(restored.tolist())
The type code is part of the format
Choose a code for the required sign, width, and range. Item size and byte order may matter across architectures; document the contract and use byteswap() only when the format requires it.
When another structure is better
NumPy offers a much broader API for vectorized math and multidimensional arrays. For binary records with different fields, struct usually expresses the layout more clearly.
Keep learning
Continue with Python Collections: Counter, defaultdict, deque & more and Python struct: pack binary data. A official Python documentation, accessed July 22, 2026, documents the API and behavior across versions.