Lists vs Arrays
Now the focus on arrays in the syllabus may cause a bit of confusion, as Python tends to use lists instead.
The following breaks down the differences between lists and arrays in Python.
Data Type
Can store mixed data types
Typically stores a single data type
Flexibility
Can hold numbers, strings, other lists
Requires all elements to be of the same type
Performance
Slower for numerical operations
Faster for numerical operations
Memory Usage
Uses more memory
More memory-efficient for large data sets
Indexing
Supports indexing and slicing
Supports indexing and slicing (NumPy has more advanced indexing)
Operations
General-purpose operations
Supports mathematical and vectorised operations (NumPy)
Library Needed?
No (built-in)
Yes (array
module or numpy
)
Example of a List
Example of an Array (array
module)
array
module)When to Use Each?
Use lists when working with different types of data.
Use arrays when working with large numerical datasets for better performance.
Last updated