7.4 Arrays Flashcards
Array (strict data structure)
A data structure that allows you to hold many items of data which is referenced by one identifier
Array rules (strict data structure)
- All items of must be of the same datatype
- An array’s size is declared during initialisation
Python Array
- There is no such “array” but list (for the rest of the cards pArray)
- A list can store any data type without the size being defined during initialisation
Function to get length of pArray
len(name_of_array)
Function to add items in an pArray
name_of_array.append(name_of_item)
Function to get the value held at that position in a pArray
name_of_array[index]
How to delete a value at a pArray with the index
del pArray[index]
Linear search procedure for a pArray
for i in pArray:
if item == i:
(do whatever)
Advantages of arrays
Easier to utilise and sort out data
Dimensional arrays
Arrays can have different dimensions, so there can be 2D and 3D arrays (arrays inside of arrays)