Menu

Arithmetic Operators

Division

Division means splitting a value into equal parts. In Python you use the forward slash / between two values. The result is the full answer, including any fractional part, so nothing is rounded away.

For example, if a 3-litre bottle of juice is poured equally into 8 glasses, each glass gets 3 / 8, which is 0.375 litres. The fractional part matters: a whole-number answer would not show the exact amount in each glass.

When a division works out exactly, Python still gives a real number. For example, 55 / 11 gives 5.0, not 5. The / operator always returns a real result, whatever the two values are.

distance_km = 21
time_hours = 4
print(distance_km / time_hours)
print(18 / 6)

Output:

5.25
3.0

Division with / is not the same as //, which gives only the whole-number part, or %, which gives the remainder. For the full answer to a division, always use /.

Practise this