Python foundations · 8 min

Variables and numbers

Name a value and use it in arithmetic.

Use = to assign a value to a name. In total = notebooks * price, Python reads both names on the right, multiplies their values, then assigns the result to total. You can assign a new value later.

Whole numbers are integers. A number with a decimal point is a float. Python uses * for multiplication, / for division, // for floor division, and % for the remainder. Use parentheses when you want to make the order of operations explicit.

Follow the example

Assignment binds each name to a value the program can reuse.

Try it yourself

Set notebooks to 5 and price to 3. Add a delivery fee of 2 to the total, then print it.

Target output

17
Show a hint

Assign a delivery variable and add it after the multiplication.

Output

Ready

Run your code to see the output here.

The first run downloads Python. Code runs in your browser. Progress and drafts are stored on this device.

Show one solution
notebooks = 5
price = 3
delivery = 2
total = notebooks * price + delivery
print(total)