# Variables and Assignment

> How a variable keeps a value under a name, and how the = sign puts it there. When a constant is better, and why hard-coding hurts.

**Course:** [Programming Basics](https://learn.benibix.com/learn/development-concepts)  
**Time:** 11 min

**After this lesson you can:**

- Create a variable and change its value
- Read the = sign the way Python does
- Replace a hard-coded value with a constant

## How a program remembers a value

A variable is a name that holds a value. You write score = 0, and from then on the name score stands for 0. Later you can write score = 10, and the old value is replaced. A program can hold thousands of variables, each with its own name and value.

The step that puts a value into a variable is called assignment. In Python it uses one = sign. Python always works out the right side first, then stores the result under the name on the left. So score = score + 10 means take the old score, add 10, and store the answer back.

That line looks wrong to anyone who knows maths, where score can never equal score plus 10. In code, = does not mean equal. It means put this value in that box. Checking whether two values are equal uses two signs, ==, which comes later in the course.

Names follow a few rules. A name can hold letters, numbers and the _ sign, but it cannot start with a number. It cannot be a keyword. Case counts, so Score and score are two different names. Python style is to write names in lower case, with _ between words, like total_price.

Some values should never change while the program runs, such as a tax rate or the number of days in a week. A constant is a name for one of these. Python has no lock for them. Instead, people write the name in capitals, like TAX_RATE = 0.2, as a sign to leave it alone.

The opposite habit is hard-coding: typing a value straight into the sums, wherever it is needed. A price list might hold 0.2 in 15 different places. When the rate changes, someone has to find all 15, and one always gets missed.

A common mistake is using a name before giving it a value. Python reads from the top down, so print(total) above total = 5 fails with a NameError. The fix is to assign first, then use.

```python
TAX_RATE = 0.2          # a constant, in capitals
price = 50              # assignment
price = price + 10      # the right side first: 50 + 10
tax = price * TAX_RATE
print(price, tax)
# 60 12.0
```
The right side is worked out first, then stored under the name on the left.

![On the left, a box named score holds 0, and an arrow leads to the same box holding 10, over the line score = score + 10. On the right, a box named TAX_RATE holds 0.2 beside a padlock, over the note that capital letters mean do not change.](https://learn.benibix.com/diagrams/prog-variables.svg)

### Example: Lucy's shop changes its tax rate

Lucy's shop script had the rate 0.2 typed into 9 lines. When the rate went to 0.15, she changed 8 of them and missed one.

One page showed the old price for a week. She then put TAX_RATE = 0.15 at the top and used the name on all 9 lines. The next change will take 1 edit.

**Words in this lesson:** [Variable](https://learn.benibix.com/term/development/variable), [Assignment](https://learn.benibix.com/term/development/assignment), [Constant](https://learn.benibix.com/term/development/constant), [Hard-Coding](https://learn.benibix.com/term/development/hard-coding)

**Question:** What does count = count + 1 do in Python?

**Answer:** It adds 1 to count and stores the new value in count. The = sign means store, not equal. Python works out count + 1 first, then puts that answer back into count.

---

Source: https://learn.benibix.com/learn/development-concepts/variables-and-assignment
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
