Choose exam board for KS4 Computer Science (GCSE)
Choose exam board for KS4 English
Choose exam board for KS4 French
Choose exam board for KS4 Geography
Choose exam board for KS4 German
Choose exam board for KS4 History
Choose tier for KS4 Maths
Choose exam board for KS4 Music
Choose exam board for KS4 Physical education (GCSE)
Choose exam board for KS4 Religious education (GCSE)
Choose exam board for KS4 Spanish

      Variables and constants in programs

      Lesson details

      Learning outcome

      I can apply appropriate naming conventions and explain the differences between variables and constants.

      Key learning points

      1. Naming conventions improve code readability and maintainability.
      2. A variable is a named piece of data stored in a computer’s memory.
      3. A variable can be accessed and changed by a computer program.
      4. Variables must be declared and assigned values in a program.
      5. Constants hold fixed values that do not change throughout the running of the program.

      Keywords

      • Variable - a named piece of data stored in a computer’s memory which can be accessed and changed by a computer program

      • Declaration - the process of stating the name of a variable or constant and defining its data type

      • Initialisation - assigning a starting value to a variable to let the compiler know that a memory location is required

      • Constant - a value that cannot be changed during the execution of a program

      Common misconception

      You can define a constant in any programming language.

      Python does not have constants. But if you want a value to be treated as a constant, it's a common naming convention for the identifier to be written in capital letters.

      Teacher tip

      Demonstrate the use of constants in a programming language that supports them. Pupils should see how constants cannot be changed once initially assigned.

      Equipment

      Pupils will need access to a device that can edit and run Python programs. Examples in this lesson use the RPF Code Editor https://oak.link/python-editor

      Licence

      This content is © Oak National Academy Limited (2026), licensed on Open Government Licence version 3.0
      except where otherwise stated. See Oak's terms & conditions
      (Collection 2).

      Lesson video

      Loading...

      Prior knowledge starter quiz

      6 Questions

      Q1.
      What does IDE stand for?

      Intelligent Debugging Engine
      Internal Data Exchange
      Interactive Design Editor
      Correct answer: Integrated Development Environment

      Q2.
      Match the terms to their definitions:

      Correct Answer:input,data sent to a program to be processed

      data sent to a program to be processed

      Correct Answer:output,information produced by a computer system

      information produced by a computer system

      Correct Answer:IDE,an application that facilitates the writing and running of programs

      an application that facilitates the writing and running of programs

      Q3.
      What feature uses colours to distinguish code elements?

      Correct Answer: Syntax highlighting

      Q4.
      What Python function is used to receive data from the user during program execution?

      Correct Answer: input()

      Q5.
      What Python function is used to display output to the user during program execution?

      Correct Answer: print()

      Q6.
      What is the primary purpose of output devices?

      to send data to the computer
      Correct answer: to display or produce information from the computer
      to store data
      to process data

      6 Questions

      Q1.
      What is a variable?

      a piece of data that cannot be changed
      a type of constant used in programs
      a value that always remains fixed
      Correct answer: a named piece of data stored in memory that can be accessed and changed

      Q2.
      What is a constant?

      Correct answer: a value that cannot be changed during the execution of a program
      a type of variable
      a naming convention for variables
      a temporary value stored in a program

      Q3.
      What is the purpose of naming conventions?

      to make the code run faster
      to reduce memory usage
      Correct answer: to improve code readability and maintainability
      to avoid using variables

      Q4.
      What is initialisation in programming?

      declaring a variable as a specific data type
      Correct answer: assigning an initial value to a variable
      assigning a value to a constant
      using a variable without declaring it

      Q5.
      Is it possible to define a constant in Python?

      Yes, Python has built-in constants.
      Yes, constants can be declared using a specific keyword.
      Correct answer: No, Python does not allow the use of constants.

      Q6.
      What variable name would be commonly used to store a first name in Python?

      Correct Answer: first_name

      To help you plan your 10 computer science lesson on: Variables and constants in programs, download all teaching resources for free and adapt to suit your pupils' needs...