DeskFluent
Module 3 Pro7 min read

Variables, text and numbers

The boxes you put things in, and why 2 + "2" causes an error.

Module 1 introduced the variable: a named box you put a value in, like writing "TaxRate" on a jar. Last lesson you saw that "7 6" in quotes behaves differently from 7 6 without them. This lesson connects those two ideas — and introduces the single most common error message in beginner Python, so it never gets to surprise you.

Boxes with labels

Type and run:

price = 100 tax = price * 0.18 print(price + tax)

Output: 118.0. The equals sign means put this value into this box. Read it right to left: work out the right-hand side, store it under the left-hand name. From then on, the name stands for the value.

Boxes can be refilled:

score = 10 score = score + 5 print(score)

That second line horrifies anyone who remembers school algebra — how can score equal score plus five? It can, because this is an instruction, not an equation: take what is in the score box, add 5, put the result back in the box. You get 15. This refill move powers half of all real code, including the running totals coming in the next lesson.

Text goes in boxes too

name = "Priya" greeting = "Hello, " + name + "!" print(greeting)

Keep reading with Pro

You are reading the free preview. Module 1 of every course is free forever — Pro unlocks the rest of this lesson, every other module of every course, removes ads, and adds workbooks and certificates.