Learn Arrays allow multiple values to be stored within a single value. In order to access a value inside an array you must supply an index. These start at 0 and go up to the length of the array less one. Try Write a program that will store 3 names into an array. Say hello […]
Learn In this lesson you will learn how to update a single value within an array. The main take home point of this lesson is to always supply an index when you need to use or update a value within an array. Try Two arrays have been created. The first stores the names of CS […]
Learn One of the core learning objectives for arrays is to understand how they link to counter controlled loops (or just counter loops). These marry so well toghether that it is rare that you will use arrays without them. Both GCSE and A-level exams will require you to make use of counter loops when using […]
About arrays
Arrays allow you to store multiple values into a single variable reference. This makes the manipulation of the data held within the array much simpler by the use of a loop.
The sample code is taken from the video.
# index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
scores = [40,20,1,49,34,41,35,37,46,32,5,3, 1, 6, 54]
# square brackets allow access to the array
x = 0
while x < len(scores):
print scores[x], "index ", x
x = x + 1
Key term
Data structure – a specific way of structuring a set of data in order to make the manipulation of that data easier.
Look at the code earlier on this page to see how you can itterate over an array. You can then print names[x] assuming that x is the variable you used to keep track!
Leave a Reply