成人论坛

Data types, structures and operators - EdexcelData types

Programs use data, known as 鈥榲alues鈥. Variables hold values. Each variable in a program must have a data type. Sometimes a programmer needs to store a lot of related data. To do this they use structures such as arrays.

Part of Computer ScienceApplication of computational thinking

Data types

Each in a must have a . The data type determines what type of value the variable will hold.

Data typePurposeExample
IntegerWhole numbers27
Real (also called Float)Decimal numbers27.5
Char (also called Character)A single alphanumeric characterA
StringOne or more alphanumeric charactersABC
BooleanTRUE/FALSETRUE
Data typeInteger
PurposeWhole numbers
Example27
Data typeReal (also called Float)
PurposeDecimal numbers
Example27.5
Data typeChar (also called Character)
PurposeA single alphanumeric character
ExampleA
Data typeString
PurposeOne or more alphanumeric characters
ExampleABC
Data typeBoolean
PurposeTRUE/FALSE
ExampleTRUE

Different data types have limitations:

  • and cannot be , ie joined together
  • numbers held in and cannot be subject to mathematical operations

Type coercion

Sometimes programmers need to change the data type of a variable. For example, an integer may need to be converted to a string in order to be displayed as part of a message. This process is known as type coercion. The following examples convert a string to an integer and an integer to a string:

str(68) returns 鈥68鈥

颈苍迟(鈥54鈥) returns 54

Type coercion is sometimes referred to as .