Knowledge organisersAdditional Programming Techniques
Arrays as fixed length or static structures
A one-dimensional (1D) array is a data structure that stores a fixed-size collection of elements of the same data type under a single name. Each element is accessed using an index (position number), starting from 0. Arrays are static, meaning their size cannot change once they are created.
array names[5] creates an array with 5 elements (index 0 to 4).names[0] = "Alice" puts "Alice" at position 0.for count = 0 to theTeam.length - 1.theTeam[count], NOT theTeam[i] if the counter is called count.range(6) gives 0-5.theTeam.length returns the number of elements. To loop from 0, use for i = 0 to theTeam.length - 1.for count = 0 to theTeam.length - 1; if theTeam[count] == studentName then return True. Use the COUNTER as the array INDEX.scores = [3, 6, 6, 9, 2, 8] → scores[2] = 6 (third element, 0-indexed). Remember arrays are ZERO-INDEXED.# Create and access a 1D array (list in Python)
scores = [10, 20, 30, 40, 50]
print(scores[0]) # 10 (first element)
print(scores[2]) # 30 (third element)
scores[1] = 25 # Update second element
# Loop through the array
for i in range(len(scores)):
print("Index " + str(i) + ": " + str(scores[i]))