DB section has been updated to add some SQL code.
An array is a data structure that can hold numerous values of the SAME TYPE. If variables are drawers to hold a single value think of arrays as filing cabinets.
Each array can hold one value in a single element.Â
When declaring an array you usually have to specify:
The Array Name
How many elements it has.
What type of data the array will be holding (although not in Python)
Pseudocode Example of declaring an Array
DECLARE allTimes INITIALLY [ 10.23, 10.1, 9.9, 10.34 ]
There are a few ways of doing this but we will use the following:
This declares an array called lotterynumbers with 6 elements that contain a NULL valueÂ
The elements are numbered from 0 to 5.Â
This can be done manually such as:
Or you can separate each value in the array with commas.
This can be quite repetitive so if prompting the user to enter arrays it is usually done using a fixed loop
This can be done manually such as:
This can be quite repetitive so if prompting the user to enter arrays it is usually done using a loop to traverse the array
This video covers basic use of an array and how to index elements