Menu

Arithmetic Operators

Arithmetic Operators

Arithmetic operators are the symbols in an algorithm or program that tell the computer to carry out a mathematical calculation on values. Each one takes the values either side of it and produces a new value, which can be stored in a variable or printed.

You need to know seven of them, and in Python 3 each one has a fixed symbol:

  • Addition (+) — puts values together, such as combining two amounts
  • Subtraction (-) — finds the difference between values
  • Multiplication (*) — works out repeated equal groups
  • Division (/) — shares a value out, and the answer may have a fractional part
  • Modulus (%) — gives the whole-number remainder left over after a division
  • Integer division (//) — gives the whole-number part of a division
  • Exponentiation (**) — raises a value to a power

Arithmetic, relational and logical

Arithmetic operators are only one family of operators. Relational operators compare two values, and logical operators work with conditions, so the symbol in front of you shows which family it belongs to.

Type of operatorJobExamples
ArithmeticCalculates a new value from values+, *, //
RelationalCompares two values, giving True or False<, >=, !=
LogicalCombines conditions, or reverses oneand, or, not

The single = used in an assignment is not an arithmetic operator either — it stores the result of a calculation in a variable, while == is relational because it compares.

A school books a coach for £216 and fills it with 32 students and 4 staff. Adding the two groups is arithmetic, and dividing the cost by the number of people is arithmetic too, so the program below calculates and prints the cost for each person.

coach_cost = 216
students = 32
staff = 4
people = students + staff
cost_each = coach_cost / people
print(cost_each)

Output:

6.0

Practise this