GCSE · Computer Science · Edexcel · Spec 1CP2

Constants

Imagine the tax rate typed into hundreds of calculations, then the rate changes. Ouch. The smarter way starts with one value that refuses to budge.

Computer Science · Constants and variables

Watch what changes — and what doesn't

Step through a tiny shop program. Two names keep getting overwritten. One never moves.

Before you press Next: which of TAX, price and total do you think will change as the program runs?

1 TAX = 0.2
2 price = 10
3 total = price + price * TAX
4 print(total)
5 price = 25
6 total = price + price * TAX
7 print(total)
8 price = 40
9 total = price + price * TAX
10 print(total)
TAXpricetotal
0.2

Output

 

Step 1: TAX is set once, right at the top. It's in capitals because that's how Python programmers say "treat this as a constant" — we'll come back to exactly what that does and doesn't promise.

1 / 10

Keep your eyes on the TAX column. Then ask which columns get overwritten.

Step 1 of 10: TAX is set once, right at the top. It's in capitals because that's how Python programmers say "treat this as a constant" — we'll come back to exactly what that does and doesn't promise..

Two ways to get a constant

Visual Basic and C#vsPython

Start with the first row — it's the one people mix up most.

Focus

What stops the value changing?

Visual Basic and C#

The language itself: a declared constant is immutable

Python

Nothing. Python has no constants — capitals are only a signal

The insight

This is the bit people blur: enforced by the language versus a convention for people reading the code.

What you write

Visual Basic and C#

Const Speed As Integer = 10 (Visual Basic) and const int Speed = 10; (C#)

Python

SPEED = 10

Who keeps it fixed?

Visual Basic and C#

The language — its value cannot change during execution

Python

The programmer — they must not write code that changes it

Computer Science · Python

Find the line that breaks the rule

CONST_SPEED is supposed to be a constant in this Python program. One line breaks the rule. Which one?

A student's program — which line goes wrong?

Why use a constant?

?

Reason it through

Why does a programmer write TAX instead of typing 0.2 into every calculation?

Link 1 of 3

First link · your turn

The tax rate changes. What does the programmer have to do to the code?

2
Locked — reveal the link above first
3
Locked — reveal the link above first

Computer Science · What does 'constant' really mean?

Which idea sounds like yours?

A shop program starts with TAX = 0.2. Later, the tax rate changes.

Which of these is closest to what you think a constant is?
How sure are you?

Computer Science · Explain it in your own words

Write it, then mark yourself

A programmer writes TAX = 0.2 at the top of a program and uses the name TAX in every calculation, instead of typing 0.2 each time. Explain why. [3 marks]

0 words · your answer stays on this page and is not sent anywhere.

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

A value that stays put while the program runs

What you need to know

  • A constant holds a value in memory just like a variable — but its value can't change while the program runs.
  • A variable holds one value at a time, so when you update it, the old value is overwritten.
  • Have a goYour friend swears: "I set score = 5, then score = 8, so the 5 is still tucked away in there somewhere." Are they right?

    No — score now holds 8 and nothing else.

    A variable holds one value at a time, so updating it overwrites the previous value.

  • Use a constant when the program needs a value available but that value will not change during execution.
  • Declaring something means stating its name and defining its data type — for a variable or a constant.
  • In Visual Basic and C# a constant is declared as one — Const Speed As Integer = 10 — and is then immutable.
  • Python has no constants, so the convention is to write the identifier in capitals, like SPEED = 10.
  • Capitals don't make a value immutable, so the programmer must never write code that changes it during execution.
  • Have a goIn Python, SPEED = 10 sits at the top and a line fifty lines later says SPEED = 25. Does Python stop the second line?

    No — nothing in Python stops it, so the programmer must not write it.

    Capital letters don't make a value immutable, so keeping SPEED fixed is down to the programmer.

  • Define constants at the top of the program, with meaningful identifiers like CONST_SPEED, so readers can see them.
  • Using a name like TAX instead of typing 0.2 everywhere means a rate change needs just a single change to the code.
  • Have a goRate change incoming! One program types 0.2 into 30 calculations. Another defines TAX = 0.2 once and uses TAX in all 30. How many places must the second one edit?

    One — the line where TAX is defined.

    A name used throughout the program instead of the value means a rate change needs a single change.

  • That single change cuts the time spent keeping code up to date and cuts errors that can be hard to find.

The big picture

A constant is a named value that stays fixed while a program runs, whereas a variable's value can change. Visual Basic and C# let you declare a real constant. Python has no constants, so programmers write the name in capitals as a signal. Using a name like TAX means one edit keeps the whole program up to date.

Key points

1A constant's value cannot change during execution; a variable's value can change and the old value is overwritten.
2Visual Basic and C# can declare an immutable constant. Python has no constants, so capitals are only a convention.
3Define constants at the top of the program and give them meaningful identifiers such as CONST_SPEED.
4A named constant like TAX means one change keeps the code up to date, with less time and fewer hard-to-find errors.

Worked example

Problem

A shop program has TAX = 0.2 at the top and works out each total with total = price + price * TAX. The tax rate changes to 0.25. What does the programmer change, and what is the new total for an item with price = 50?

⚠ Watch out

Thinking a constant can never be edited, or that writing a Python name in capitals makes it unchangeable. Fixed means fixed while the program runs. Python only signals it by convention, and the programmer changes the value by editing its one definition.

🧠

Memory hook

Variables vary, constants stay put — and a name like TAX means you only ever edit one line.

✓

Check yourself

Without looking: what do a constant and a variable share, and what is the one difference? Then say what capital letters do, and don't do, in Python.

Flashcards

(12)
What is a constant?
A value held in memory that cannot be changed during the execution of a program.
What do a constant and a variable have in common?
Both hold a value in a memory location that the program needs while it runs.
What happens to a variable's old value when it is updated?
It is overwritten. A variable holds only one value at a time.
When should you use a constant rather than a variable?
When a value needs to be available to the program but will not change during execution.
What does declaration mean?
Stating the name of a variable or constant and defining its data type.
How is a constant declared in Visual Basic and in C#?
Visual Basic: Const Speed As Integer = 10. C#: const int Speed = 10; The constant is then immutable.
Does Python have constants?
No. The convention is to write the identifier in capital letters, for example SPEED = 10.
Do capital letters make a Python value immutable?
No. They only signal to readers; the programmer must not write code that changes the value during execution.
Where are constants usually defined, and why?
At the top of the program, so that people reading the code are aware of them.
What makes a good identifier for a constant?
A meaningful name that makes its purpose clear, for example CONST_SPEED.
Why use TAX instead of the value 0.2 throughout a program?
A clearly identified name is used instead of the value, so if the rate changes only a single change to the code is needed.
Two benefits of using constants?
It reduces the time taken to keep the code up to date, and reduces errors that can be hard to find.

Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.

Learning with Lightbulb is opening soon

You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.

Keep me posted

More Edexcel GCSE Computer Science topics

See the full Edexcel Computer Science curriculum →

How this lesson was checked. This Edexcel GCSE Computer Science (specification 1CP2)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 9 October 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.