Skip to content
Tactiverge

Computer engineeringLevel 2 · Builder

Variables, types and expressions

A program stores values under names called variables. In Python, writing current = voltage / resistance means: work out the right-hand side, then store the result under the name on the left, so the equals sign is an instruction rather than a claim of equality. Every value has a type, such as an integer, a floating-point number, a string of text or a list, and the type decides which operations make sense. Expressions combine values with operators that follow precedence rules, so brackets matter. Floating-point numbers are stored in binary and are usually approximate, which is why 0.1 + 0.2 is not exactly 0.3 and why results should be compared within a tolerance rather than tested for exact equality.

Why it mattersA battery-life calculation whose inputs are named variables with stated units can be checked and rerun by a teammate in seconds.

Learn it

  1. 1Values, variables and expressionsComputational Engineering · Python fundamentals