Python data types and type casting

Python has a small set of built-in data types you'll use all the time in GCSE Computer Science: strings for text, integers for whole numbers, floats for decimals, and booleans for True/False. This unit covers what each one is for, how to convert between them (casting), and — the single most common early bug — why int() is needed after input() when you want to do arithmetic on a number the user typed. Every example runs in the browser, so pupils see the type errors and the fixes for themselves. Perfect for classroom teaching, GCSE and A Level revision, and independent or home-schooled learners.


What you'll learn

  • Recognise the four core Python types: str, int, float, bool
  • Convert with int(), float(), str() (type casting)
  • Understand why input() always returns a string, even if the user types a number
  • Use type() to check what type a value has
  • Combine typed data cleanly in expressions and print output

UK GCSE topic coverage

  • Data types & casting
  • Input handling
  • Casting
  • Casting & expressions
  • Numeric types
  • Operators `/` and `//`
  • Output formatting
  • `round()` function
  • Applied arithmetic
  • Error identification
  • End-of-topic synthesis

Worked example

Cast input to int() so arithmetic works

age_text = input("How old are you? ")
age = int(age_text)
print("Next year you'll be", age + 1)

Try a full unit free with a RunPy account

Sign up free and get the whole of Unit 1 (Input, Output and Variables) with checked tasks and instant feedback, plus a selection of the exam-style questions so you can practice on real GCSE-style content before upgrading.


Lessons in this unit

Full interactive lessons with checked tasks are available to signed-in RunPy users. Unit 1 and a selection of exam-style questions are free with a RunPy account.

  1. Data Types
  2. Input is always text
  3. Converting text to integers
  4. Multiple casts and expression order
  5. Converting text to floats
  6. Type behaviour and division
  7. Formatting calculated output
  8. f-strings for output
  9. Rounding numbers
  10. Multi-step calculations from input
  11. Debugging input errors
  12. Applied mini challenge

Frequently asked questions

Why does 'int' + 'int' give a TypeError when I read numbers from input()?
input() returns a string. Adding two strings concatenates them; converting each to int() first with int(input(...)) fixes the type error and gives real arithmetic.
Which exam boards cover data types?
All UK GCSE Computer Science specifications (OCR J277, AQA 8525, Edexcel, Eduqas, WJEC) require pupils to identify and use the four core data types and cast between them.
Is bool a separate type from int?
Booleans are technically a subclass of int in Python (True == 1, False == 0), but for GCSE it's simplest to treat them as their own type with values True and False.