S7 - 33 Arrays, tupules and records Flashcards
what is an array?
A finite, ordered set of elements of the same type
what does an array do?
An array holds a finite set of elements which are then assigned with an index number
how can we reference any element in an array?
by entering an integer in square brackets in front of a variable.
e.g.
birdname = [“robin”, “blackbird”, “pigeon”]
birdname [2] = pigeon
how can we return the length of an array?
cars = [“porsche”, “lamborghini”, “mclaren”,]
cars - this is an array and holds all these strings
the function len[cars] will assign an integer (this shows how many cars it holds)
e.g.
numcars = len[cars]
print(numcars) # it will print the integer 3 on the screen
LOOK AT PSEUDOCODE IN PAGE 180
To find the position of a bird in an array
page 180
what are the 2 arrays?
+ 1-dimensional array
+ 2-dimensional arrays
how many dimensions can an array have?
An array can have 2 or more dimensions
list 4 elementary data types
+ integer
+ real
+ boolean
+ char
what is a tuple?
An ordered set of values that could be elements of any type
whats the difference between arrays and a tupule
Unlike arrays, the elements do not all have to be the same time
a tuple is immutable, what does this mean?
like a string the elements cannot be changed
state the advantages and disadvantages of a tuple
- elements cannot be changed
- isn’t dynamic, cannot add or remove items
+ elements do not all have to be the same type