Introduction to Constants
What's a Constant?¶
A Constant is a value that isn't supposed to change while you are running your program. They are also known values that never change, like PI.
They look a lot like variables, but since they shouldn't change we call them constants.
How do we use Constants?¶
constkey word rather than the
letkeyword when you want a constant.
To set up constants, we use a different naming convention and put them in a different place.
1 2 3
That's right we, by strong convention, name constants using ALL CAPS. And, we also assign the value to a constant right when we declare it.
If we have a constant name that is more than one word we use the underscore
_to separate the words.
1 2 3 4 5
- Oh, one final thing, we need to declare constants before we declare variables.
1 2 3 4 5 6 7 8 9
New Coding Standard
Be sure to follow the naming conventions so that you as a programmer can distinguish variables from constants just by glancing at their names.