Arrays
Syntax
arr |
= |
[ |
32,54,11 |
] |
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.
Helpful links
Pwnict – introduction to python arrays
Test your skill
1. Create an array which stores three names. Call the variable names.
2. Display the second name ONLY from the array you created in task 1.
3. Attempt the Every Tom, Dick and Harry task











