# 5 Operators in Python A function is an idealization of how a varying quantity depends on another quantity. It was elaborated upon with the infinitesimal calculus in the 17th century and later formalized in terms of set theory in the 19th century.

Operators are evaluated from right to left. For example, 3 + 4 will be evaluated before 2 + 3. This is called operator precedence.

The arithmetic operators add, subtract, multiply, divide, and exponentiate values. They can be used with integers or real numbers. arithmetic operations are evaluated from left to right.

The concatenation and repetition operators take two sequences and return a new sequence of the same type. The order of the operands doesn’t change the result.

The + (plus) operator is an arithmetic operator that sums up two numbers and produces a value. It can be used in conjunction with a variable to create an assignment that’s equivalent to a function call. You can also perform the same operation manually by passing two values separated with a plus sign to the ADD function.

## Subtract

The opposite of adding, subtraction takes a number away from another. Students need to learn how to subtract numbers as well as add them.

As with addition, the order of operations is important. Unlike multiplication and division which can be done in any order, subtraction must be done in the same order as addition: from left to right.

Other names for subtraction include Minus, Less, Difference, Decrease and Take Away. This is because subtraction can be used in a general or figurative way as well as being a more concrete and practical way of saying the diminution of a sum or quantity: to deduct taxes from a paycheck. Subtraction has the commutative property, meaning that the value of the subtracted number can be moved around and will equal the original number being subtracted from.

## Multiply

Multiplication is the process of repeating a sequence of values. It is a quicker method for calculating how many objects there are than repeated addition. Fluent multiplication reduces the cognitive load associated with later learning of division.

Use the repetition operator (*) to multiply a tuple or list of integers. The order of the operands doesn’t affect the result.

The multiplication identity is 1. A number multiplied by itself always equals that number. Multiplication is also related to the distributive property, which states that the products of two or more operations are the sums of each individual operation. Python evaluates all operators in an expression from left to right, so it first calculates any multiplication or division that may be present. Afterwards it computes the addition and subtraction.

## Divide

As the name suggests, division splits numbers into equal parts or groups. It is one of the 4 main arithmetic operations alongside addition, subtraction and multiplication (the inverse of division).

It can be tricky for children to grasp division when it involves sharing a number between multiple groups. Try using blocks to help them and encourage them to think about how many groups a certain number can be divided into, e.g. 4 blocks / 2 groups = 2.

Year 3 students will need to learn how to divide numbers by a single digit and may also encounter long division questions that require them to work out a remainder. This can be confusing for some children, so try introducing the bus stop method as an alternative.

## Assign

There are several assignment operators in Python that allow you to assign a value to a variable. These include: +=, -=, *=, /=, and %=. These can be combined with arithmetic operators to perform an operation and assign the result to a variable in one step.

#### Logical Operators

The logical operators, or Boolean operators, take two Boolean values and combine them to produce a third value that can be either true or false. These include AND, OR, XOR, and NOT.

An augmented addition operator (++) allows you to increment an accumulator or counter variable in place of adding it. This is also sometimes referred to as a lazy evaluation. Using this operator avoids the NameError that would otherwise be generated by an expression like const total = total + 5. This is because the value of the accumulated number is assigned back to the variable, rather than evaluated.