All subjects · Computer Science · WCP02 Practical Programming and Problem-solving
Data types and type conversion
Edexcel IAL Computer Science · WCP02 Practical Programming and Problem-solving
Every value has a data type, which decides what you can do with it. Many Unit 2 errors come from using the wrong type.
The data types (spec 8.1.1)
| Type | Python | Examples | Notes |
|---|---|---|---|
| Integer | int | 42, -7, 0 | Whole numbers of any size |
| Real | float | 3.5, -0.25, 2.0 | Numbers with a decimal point; stored approximately |
| Boolean | bool | True, False | Capital T and F |
| String | str | "hello", "42", "" | A sequence of characters in quotes; immutable |
| Character | str of length 1 | "A", "7", " " | Python has no separate char type |
Converting between types
int(), float(), str() and bool() convert values; type() tells you a value's type.
print(int("25") + 5)
print(int(7.9))
print(float("2.5") * 2)
print(str(19) + "99")
print(bool(0), bool(3), bool(""), bool("no"))
print(type(3), type(3.0), type("3"))Output:
30
7
5.0
1999
False True False True
<class 'int'> <class 'float'> <class 'str'>int() on a float truncates (cuts off the decimal part). int("7.9") fails with ValueError: convert with float() first.
Characters and codes
ord() gives the character code of a single character and chr() turns a code back into a character. Capital letters A to Z are codes 65 to 90 and lower case a to z are 97 to 122.
print(ord("A"), ord("a"), chr(66))
letter = "c"
print(chr(ord(letter) - 32))Output:
65 97 B
CChoosing a type
Use int for counts and indexes, float for measurements and money calculations, bool for flags, str for text and for 'numbers' that are identifiers, such as phone numbers or postcodes, which can start with 0 and are never used in arithmetic.
Worked example
A user types 3.75 into input(). How do you get the whole number of pounds and the number of pence as integers?
- value = float("3.75") gives 3.75
- pounds = int(value) truncates to 3
- pence = round(value * 100) % 100 gives 75
Answer: pounds = 3, pence = 75
Check yourself
- What is displayed when this code runs?
```python
print(int(9.99))
```
Show answer
9. int() truncates towards zero, so 9.99 becomes 9.
- What is displayed when this code runs?
```python
a = "5"
b = "3"
print(a + b)
```
- 8
- 53
- 5 3
- Error
Show answer
53. Both are strings, so + joins them: 53.
- Which exception is raised when this code runs?
```python
n = int("4.5")
```
- TypeError
- ZeroDivisionError
- NameError
- ValueError
Show answer
ValueError. "4.5" is a string, but not a valid integer, so int() raises ValueError. Use float() first.
- What is displayed when this code runs?
```python
print(bool(""), bool("False"))
```
- False True
- False False
- True True
- True False
Show answer
False True. An empty string is False; any non-empty string, even "False", is True: False True.
- What is displayed when this code runs?
```python
print(ord("D") - ord("A"))
```
Show answer
3. Codes are consecutive: 68 - 65 = 3.
- What is displayed when this code runs?
```python
print(chr(ord("m") - 32))
```
Show answer
M. Lower case codes are 32 more than upper case ones, so this gives M.
- What is displayed when this code runs?
```python
x = 10 / 5
print(type(x))
```
- <class 'int'>
- <class 'str'>
- <class 'float'>
- <class 'bool'>
Show answer
<class 'float'>. / always produces a float, even when the answer is whole: <class 'float'>.
- Which data type is most suitable for storing a mobile phone number such as 07700900123?
- Integer
- Real
- Boolean
- String
Show answer
String. It starts with 0, which an integer would lose, and you never do arithmetic on it.
Sources
- Pearson Edexcel International Advanced Subsidiary/Advanced Level in Computer Science specification (XCP01/YCP01), first teaching 2026
- Pearson IAL Computer Science Unit 2 Programming Language Subset (PLS), Python 3
- Pearson IAL Computer Science IAS sample assessment materials (Unit 2 paper and mark scheme)
Last updated 8 November 2026. Spotted a mistake? Tell us.