Data Types (2.3.a, 2.3.b, 2.3.c)
There are six key types of data:
|Integer||27||Any whole number|
|Real number||3.14||Any rational number (including integers). Known as a "floating point number" or simply a "float" in python.|
|Boolean||True||Only true or false (although boolean values can be represented as on or off, 1 or 0, e.t.c.). Typically stored in exactly one byte.|
|Character||"e"||Stored in one byte (for ASCII). The character can be any character within the character set.|
|String||"Almost never is an interesting concept"||A string is simply a block of text. It can be any size, although longer strings can impact performance.|
|Array||['James', 'Harry', 'Anna']||There are two types of array - a 1 dimensional array (a "list" or a "tuple" in python) and a 2 dimensional array (a "dictionary" in python).|
An array is initialised in exactly the same way as a variable (in Python). Here is an example "serial" list searching algorithm written in Python:
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 search a list called li for example, and print "this is an example function" if it finds an item called example.
It's important that data is stored as the correct data type for the problem being solved. For example, if arithmetic is going to be performed, then data needs to be stored as integers or real numbers. If a remainder is needed from a division, then real numbers need to be used. If a phone number is being stored, then strings should be used, because the leading zeros are important (01732 is not the same as 1732!).