±«Óătv

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 .