Computer Science Essentials, Unit 2, Lesson 1 of 6

Data types and operators

GCSE Computer Science, Programming, 20 minutes

Sign in

Integer, real, Boolean, character and string; variables and constants; MOD, DIV, precedence and Boolean logic.

What you will learn

  • Choose the right data type for a value
  • Use MOD and DIV
  • Work out expressions in the right order
  • Evaluate AND, OR and NOT

Five data types

Every value in a program has a data type, which decides what can be done with it.

TypeHoldsExamples
Integerwhole numbers17, -3, 0
Real (float)numbers with a decimal part8.50, 21.4
Booleanone of two valuesTrue, False
Characterone single character"B", "?"
Stringtext, any length"LS1 4AP", "07700 900123"

A phone number is a string: it starts with 0 and nobody adds phone numbers together.

Casting changes a value's type: str(7) gives the text "7", int("42") gives the number 42. Joining two strings with + sticks them together: "4" + "5" is "45", but 4 + 5 is 9.

So int("3") + int("8") is 11, because both are turned into numbers first. AQA writes these casts as STRING_TO_INT, INT_TO_STRING and STRING_TO_REAL; float() in Python turns text into a real.

A variable is a named place in memory (a named location) whose value can change while the program runs. A constant keeps the same value for the whole run, such as const VAT_RATE = 0.2, so it cannot be changed by mistake and is easy to update in one place.

The rest of this lesson and its 7 practice questions are locked.

In this lesson

  1. Five data types
  2. Arithmetic, MOD and DIV
  3. Comparisons and Boolean operators
  4. Try it: MOD and DIV

7 practice questions, marked as you go; about 20 minutes in all.

Key terms

Data type, Casting, Variable, Constant, DIV, MOD, AND, NOT

In this unit: Programming

Data types, operators, selection, loops, arrays, strings, subroutines, robust programs, SQL and files, read and traced step by step.

All of Programming