What is the difference between a variable and a constant?
A variable is a named place in memory that holds a value, and the value can change while the program runs. A constant also has a name and a value, but the value is not supposed to change after it is set.
Examples: 1) A variable: a score in a game. It starts at 0 and goes up as the player earns points. 2) A constant: a value like the number of days in a week, or a tax rate your program uses everywhere. 3) Using a constant gives the value a meaningful name and means you only need to change it in one place if it ever changes. 4) Some languages enforce constants with a keyword such as const or final. Others, such as Python, rely on a naming convention, usually capital letters like TAX_RATE.
A good habit is to use names that say what the value is, such as total_price, not x.
Can you think of a value in your own project that should be a constant?