MEPX
Chapter 3 of 15All chapters

Chapter 3 of 15

Variables

Names point at values, and the value carries the type.

Assignment

A variable is created the moment you assign to it, with no declaration keyword. The name is a label pointing at an object, so assigning again just moves the label.

  • count = 3 then count = "three" is legal, because the type belongs to the value.
  • Names use lower_case_with_underscores by convention.

Several at once

Python can unpack in one step: a, b = 1, 2 assigns both, and a, b = b, a swaps them without a temporary variable.