I Haz Codes

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Menu
Accessing a value
Updating a value
Loops and arrays
Arrays

Syntax

arr
=
[
32,54,11
]

Accessing a value

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 […]

Updating a value

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 […]

Loops and arrays

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.

Helpful links

Pwnict – introduction to python  arrays

Functions to use with lists

Further information on arrays

Test your skill

1. Create an array which stores three names. Call the variable names.

Task 1: Answer SelectShow

2. Display the second name ONLY from the array you created in task 1.

Task 2: Answer SelectShow

3. Attempt the Every Tom, Dick and Harry task

Task 3: Hint SelectShow

Leave a Reply

Your email address will not be published. Required fields are marked *

Information