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.22 price = 103 total = price + price * TAX4 print(total)5 price = 256 total = price + price * TAX7 print(total)8 price = 409 total = price + price * TAX10 print(total)
| TAX | price | total |
|---|---|---|
| 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.
Keep your eyes on the TAX column. Then ask which columns get overwritten.
Why use a constant?
Reason it through
Why does a programmer write TAX instead of typing 0.2 into every calculation?
First link · your turn
The tax rate changes. What does the programmer have to do to the code?
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
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?
What do a constant and a variable have in common?
What happens to a variable's old value when it is updated?
When should you use a constant rather than a variable?
What does declaration mean?
How is a constant declared in Visual Basic and in C#?
Does Python have constants?
Do capital letters make a Python value immutable?
Where are constants usually defined, and why?
What makes a good identifier for a constant?
Why use TAX instead of the value 0.2 throughout a program?
Two benefits of using constants?
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 postedMore Edexcel GCSE Computer Science topics
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.