Skip to content
Learnearn.uk » Home » Constants & Variables

Constants & Variables

Introduction

Constants & Variables

When we want to write computer programs we often need to store simple pieces of data temporarily in the program for further use. We do this using a combination of constants and variables, using the format name = value.

Constants

Whenever we store data that doesn’t change we store it in a constant, usually designated in Python as all capitals.

For example if we want to store the value of Pi, we can create a PI constant.

PI = 3.142

Variables

If we want to store the value of some data that might change, we use a similar system, but instead we use lowercase letters.

player_name = "Bob"

It is important to note that Python and many other programming languages don’t recognise the difference between variables and constants and so they will let you change a constant, even if you shouldn’t!

Naming Conventions

Reserved Words

Resources