2.2: Data Types
Exam Board:
OCR
Specification:
J277
What are the different data types?
When programming, variables should be given appropriate data types.
Character
A single character, such as a letter, number or punctuation symbol.
​
Examples:
T
8
?
String
A sequence of characters, including letters, numbers and punctuation.
​
Examples:
Harry Waters
14:50pm
Ice Age 4
Integer
A whole number.
​
​
​
Examples:
475
-8432
56732
Real
Boolean
A decimal number.
​
​
Examples:
65.3
-321.1234
909.135
An answer that only has two possible values.
​
Examples:
True / False
Yes / No
0 / 1
Telephone numbers are always stored as a string, not an integer.
Casting
Converting the value of a variable from one data type into another is known as casting.
​
Python automatically assumes an input is a string so the int() command is used to cast an input into an integer. Other Python commands for casting include str() and float().
​
For example:
age = int(input("Enter your age: "))
Questo's Questions
2.2 - Data Types:
​
1. List the five data types, giving an example of each. [5]
​
2. State which data type is most suitable for the following variables:
-
a. Age [1]
-
b. Surname [1]
-
c. Height (in metres) [1]
-
d. First Initial [1]
-
e. Phone number [1]
-
f. Right-Handed? [1]
​​
3. Explain what casting is and give a programming situation in which it would be used. [2]