Wednesday, November 26, 2014

Array

NUMERIC DATA TYPES
This is an integer, so whole number eg 7 or a Real number so 7.2.
ALPHANUMERIC DATA TYPES
This is a CHAR so single character or digit, eg ‘C’.
String, several characters together, like star citizen.
BOOLEAN
Data that can only take two values so true or false.


ARRAY OF DATA
contains several data items, usually of the same type, grouped with a single name. Accessed using an index, Stored continuously within computer memory.
continuously means like all together, in sequence.
In Python an array is called a list.
If you have a list/array you can easily add things to the list and take away from the list without changing the source code on the fly. This also allows more flexibility with using it other than storing each one as a separate variable.


li = ['a', 'b', 'new', 'mpilgrim', 'z', 'example', 'new', 'two', 'elements']  
for item in li:  
   if item == 'example':  
       print "this is an example function"


This will go through the list until it finds “example” and it will print the text.
a one dimensional array as one row whereas a two dimensional array has an unlimited amount of rows and columns, similar to a spreadsheet.
all arrays start at position 0
so in: M A R A D; M is in position 0 and A is in pos 1
0 is still the first character/part of the array.

An array is used to make a program more efficient when it comes to a lot of data, it is also good for iteration as it means you can eliminate using each variable separately. Arrays are dynamic.

No comments:

Post a Comment