Revise Computing
Revision notesQuestionsFor schools
Log inStart revising free
Revision notesQuestionsFor schoolsLog in
GCSE Computer Science/Supplementary programming practice/Data Types and Casting

Fix type errors

301.4 Data Types and Casting

Practise exam questions

Data Types and Casting — Note 4 of 4

Correct invalid type usage.

What you need to know

A TypeError happens when you use an operator on incompatible types, such as adding a string and an integer. The fix is to cast one value to match the other.

What to know

  • "5" + 3 causes TypeError — can't add str and int
  • Fix: int("5") + 3 or "5" + str(3)
  • input() always returns str — cast before maths
  • Read the error message to find the mismatched types

Code examples

Fixing a type error
python
age = input("Age: ")  # returns "15" (str)
# age + 1  ← TypeError!
age = int(age)
print(age + 1)  # 16
← Previous noteCasting301.4 Data Types and CastingNext topic →String concatenation301.5 Concatenation and Basic Strings

Back to Data Types and Casting

Specification notes for programming are in Paper 2.

Data Types and Casting

Note 4 of 4

  1. 1Common data types
  2. 2Choosing types
  3. 3Casting
  4. 4Fix type errors
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).