Revise Computing
Revision notesQuestionsFor schools
Log inStart revising free
Revision notesQuestionsFor schoolsLog in
GCSE Computer Science/Paper 2/Data Types

Casting

2.2.2 Data Types

Practise exam questions

Data Types — Note 2 of 2

converting data types during the execution of a program e.g. Str() Int() Float()

What you need to know

Casting is the process of temporarily converting a value from one data type to another. This is often needed when input is received as a string but needs to be used as a number, or when a number needs to be joined to a string for output. Common casting functions include int(), float(), str(), and bool().

What to know

  • int() converts a value to an integer, e.g. int("5") gives 5.
  • float() or real() converts a value to a decimal number, e.g. float("3.14") gives 3.14.
  • str() converts a value to a string, e.g. str(42) gives "42". Needed for concatenation with strings.
  • bool() converts a value to a Boolean, e.g. bool(1) gives True.
  • Input from the user is always received as a string, so casting to int or float is often needed before calculations.

Key terms

Casting

Converting/changing one data type to another.

Exam technique

  • Tip:The definition is 'converting one data type to another' — not 'change to string' (that's an example, not a definition).
  • Example:staffID = surname + str(year) — str() casts the integer year to a string for concatenation.
  • Example:int(message.right(4)) * 2 — casts the last 4 characters to integer before multiplying.

Code examples

Casting in Python
python
# Input is always a string, so we cast to int
age = int(input("Enter your age: "))

# Cast int to string for concatenation
print("You are " + str(age) + " years old")

# Cast string to float
price = float("9.99")
print(price + 1)  # Output: 10.99

Ready to test yourself?

Practise 2.2.2 questions
← Previous noteData types2.2.2 Data TypesNext topic →Concatenation2.2.3 Additional Programming Techniques

Back to Data Types

Revise another OCR GCSE topic: Programming Fundamentals

Data Types

Note 2 of 2

  1. 1Data types
  2. 2Casting
Topic overview

© 2026 Revise Computing · revisecomputing.co.uk

Privacy noticeTermsContact

Revise Computing is an independent revision resource. It is not affiliated with, or endorsed by, OCR (Oxford Cambridge and RSA Examinations).