Skip to content

Stockertim Dictionary · Technology

Variable

Also called programming variable, variable in code, variable assignment

In short

In programming, a name that refers to a stored value, such as a number, some text or a list, so the value can be reused and changed later in the code.

  • Beginner
  • Concept
  • Checked

In detail

A variable gives a value a name. In Python, the line rate = 0.2 creates a variable called rate that refers to the number 0.2, and later lines can use rate wherever that number is needed. Assigning again, such as rate = 0.25, makes the name refer to the new value; the old one is forgotten.

Every value has a type, and the type decides what operations make sense. Whole numbers are int, numbers with a decimal point are float, text in quotes is str and True or False is bool. Python works out the type from the value, so the same name can hold a number on one line and text on another, which is convenient but allows mistakes to pass unnoticed.

Good names make code readable. monthly_rent tells a reviewer far more than x, and a reader can check a calculation such as annual_rent = monthly_rent * 12 at a glance. Python names are case-sensitive, cannot start with a digit and conventionally use lower case with underscores. Names that copy a built-in function, such as sum or list, hide that function for the rest of the program.

Variables also explain many beginner errors. Using a name before it has been assigned raises a NameError. Text read from a file or a form arrives as str even when it looks like a number, so '5' + '5' gives '55' rather than 10. Converting with int() or float() at the point where data enters the program avoids that class of mistake.

Worked example

A freelance designer in Lagos writes a few lines of Python to price a job.

  1. hours = 40 and day_rate = 50000 are set as variables, with eight hours to a working day.
  2. fee = hours / 8 * day_rate gives 40 / 8 × 50,000 = 250,000
  3. Changing hours to 48 and running the lines again gives 48 / 8 × 50,000 = 300,000

The price updates from one changed value, and every line can be read and checked by name.

In practice

Analysts use variables to hold file paths, dates, thresholds and intermediate results, keeping assumptions at the top of a script where they can be found and changed. Spreadsheet users get a similar benefit from named cells, which replace a cell reference with a readable name.

Watch out

  • Values typed into a program by hand are hard-coded; when they change often, read them from one clearly labelled place.
  • Numbers read as text join instead of adding; convert the type as soon as data comes in.

Learn it properly

Official sources

Facts last checked on 9 November 2026.

Education, not advice: the Stockertim Dictionary explains what terms mean. It never recommends buying or selling anything.

English