Arrays

What is an Array?

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.

Structure of an array

Each array can hold one value in a single element.

When declaring an array you usually have to specify:

  1. The Array Name

  2. How many elements it has.

  3. 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 ]

Declaring an Array in Python

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.

Entering Data into an array

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 fixed loop

Printing Data from an Array

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

Array Tutorial Video

SDD 1.1 Arrays.mp4

This video covers basic use of an array and how to index elements