Skip to content
BENIBIX Learn

Variable

Development🧩 Programming ConceptsData and Variables

A named box in a program that holds a value. The value can change.

Think of it like

Think of it like a box with a name on the lid. You can put something in, look inside, or swap it.

Example

A game keeps the player's points in a variable called score. Each coin adds 10, so score goes 0, 10, 20.

Why it matters

Programs remember things in variables. Without them, a program could not keep a score, a name or a total.

Definition

A variable is a name that holds a value in a program. You pick the name, like score or price, and give it a value. Later you use the name instead of the value. The value can change while the program runs, which is why it is called a variable. Good names make code much easier to read.

Example code

python
>>> score = 0
>>> score = score + 10
>>> score
10
The box called score starts at 0. One coin later it holds 10.

Common mistake

Picking names like x or data2. A name like total_price tells the next reader what is inside.

Key takeaways

  1. 1
    A name and a value. The name points to what is stored.
  2. 2
    Can change. A new value can replace the old one.
  3. 3
    Name it well. Say what is inside, not just a letter.

Learn it properly