There are a number of built-in data structures you can choose from when it comes to implementing arrays in Python. In this section, you’ve focused on core language features and data structures included in the standard library.
If you’re willing to go beyond the Python standard library, then third-party packages like NumPy and pandas offer a wide range of fast array implementations for scientific computing and data science.
In this section you learned:
- To store arbitrary objects, potentially with mixed data types use a
list
or atuple
- When you need mutability choose a
list
- For numeric data where memory and performance is important select
array.array
- For textual data represented as Unicode characters use the built-in
str
- For a mutable string-like data structure use a
list
of characters - For storing a contiguous block of bytes use immutable
bytes
type or abytearray
In most cases, you should start out with a simple list
. You’ll only need to specialize later on if performance or storage space becomes an issue. Most of the time, using a general-purpose array data structure like list
gives you the fastest development speed and the most programming convenience.
RobyB on Feb. 24, 2021
Thank you!