One- and two-dimensional arrays, looping through them, and string handling: length, substrings, character codes and concatenation.
Arrays
An array holds several values under one name.
Each item has an index, starting at 0.
scores = [12, 7, 19, 4]
print(scores[0])
print(scores[scores.length - 1])scores ← [12, 7, 19, 4]
OUTPUT scores[0]
OUTPUT scores[LEN(scores) - 1]scores = [12, 7, 19, 4]
print(scores[0])
print(scores[len(scores) - 1])This prints 12, then 4: the last index is always the length minus 1. A loop from 0 to length - 1 visits every item.
A 2D array is a table: grid[row, column] in OCR style, grid[row][column] in AQA style and Python. The first index picks the row.
The rest of this lesson and its 7 practice questions are in Plus.
Screen 1 of 3, free to read.
- 7 exam-style questions, marked as you go, each with a worked solution
- Anything you get wrong is saved to your flashcards