Summary
Highlights
Arrays are like variables that can hold multiple data items, stored in a contiguous block of memory. Unlike Python lists, true arrays are contiguous. They are typically zero-indexed, meaning the first item is at index 0.
In Python, lists behave like arrays, even though internally Python might move the data to maintain contiguity when items are added. An example shows creating a one-dimensional array of country names and accessing elements by index.
Arrays are static data structures, meaning their size cannot be changed after creation. Python lists abstract this by moving the entire data structure to a new memory location if the size changes.
A three-dimensional array can be visualized as a cube, requiring three index values (height, length, depth) for access. Computers can easily handle higher-dimensional arrays (fourth, fifth, etc.) by extending this concept, although human visualization becomes more complex.
Records are data structures that group related fields, where each field can have a different data type. They are not available in Python but are common in other languages like Visual Basic. Using a 'T' prefix for record names is a common convention.
There are three steps to using records: defining the structure (listing fields and their data types), declaring variables or arrays to use the record structure, and then assigning and retrieving data. An example in Visual Basic demonstrates these steps using a 'TCar' record.
Python uses lists as its version of arrays and also supports tuples. Both share similarities with arrays, but a key difference lies in their mutability. Tuples are immutable (cannot be changed after creation), while lists are mutable (can be changed, grown, or shrunk).
An example demonstrates modifying a Python list: initially setting it up, adding new items using `.append()`, and updating existing items by assigning new values to a specific index. This highlights the mutable nature of lists.
An example demonstrates a Python tuple's immutability: initially setting it up (using parentheses instead of square brackets like lists), and then attempting to update an element. This attempt will result in an error, proving that tuples cannot be changed after creation.
A two-dimensional array can be visualized as a table with rows and columns, each requiring two index values for access. While Python lists can hold different data types, arrays in most languages are typically homogeneous, holding only one data type.