1. Arithmetic

Operators are symbols that combine values. The values they combine are operands, and the whole expression produces a result.

Python's basic arithmetic operators:

OperatorMeaningExampleResult
+addition7 + 310
-subtraction10 - 46
*multiplication6 * 742
/division10 / 42.5

+, -, * and / are binary operators: they need one operand on each side.

/ always returns a float, even when the division is exact:

+, - and * keep the type of their operands: two int values produce an int, and an operand that is a float produces a float.

Variables can be operands too:

#01

Add two numbers

Use the addition operator (+) to add 7 and 3, and print the result.

Print exactly:

Create a free account to save your progress and unlock chapter 2.

#02

Subtract two numbers

Use the subtraction operator (-) to subtract 4 from 10, and print the result.

Print exactly:

Create a free account to save your progress and unlock chapter 2.

#03

Multiply two numbers

Use the multiplication operator (*) to multiply 6 by 7, and print the result.

Print exactly:

Create a free account to save your progress and unlock chapter 2.

#04

Divide two numbers

Use the division operator (/) to divide 8 by 2, and print the result. Division always returns a float, even when the result is exact.

Print exactly:

Create a free account to save your progress and unlock chapter 2.

#05

Multiply with variables

Store 12 in a variable named price and 3 in a variable named quantity. Print the result of multiplying them with *.

Print exactly:

Create a free account to save your progress and unlock chapter 2.