Variables and assignment

A variable is a name for a value. = stores a value, and the right side is worked out first.

Syntax

name = value
name += 5 # same as name = name + 5
  • Names use letters, digits and underscores, and cannot start with a digit.

Example

battery = 80
battery = battery - 25
print(battery)

Output:

55

Common mistakes

  • = stores, == compares. Writing if x = 5 is a syntax error.
  • A name must be spelled the same way every time; Python does not guess what you meant.

Practise it