BeginnerTopic 4 of 104Software & Computing

Operators and expressions

Arithmetic, comparison and logical operators combine values.

In depth

Arithmetic (+ - * / %), comparison (== != < >), logical (and, or, not) and bitwise operators build expressions. Operator precedence and associativity decide evaluation order; parentheses make intent explicit. Integer division and floating-point rounding differ across languages.

Key points

  • Short-circuit evaluation
  • Modulo for cyclic behaviour
  • Beware = vs ==
Example

7 // 2 is 3 and 7 % 2 is 1 in Python.

Why it matters

Operators and expressions combine values to make decisions and calculations, so mistakes here change the logic of the whole program.

Where this is used

  • Computing a total price with arithmetic operators.
  • Checking that a value is within a range with comparison operators.
  • Combining two conditions for an access rule with logical operators.

Frequently asked questions

What is Operators and expressions?

Arithmetic, comparison and logical operators combine values.

Why is it important to understand operators and expressions?

Operators and expressions combine values to make decisions and calculations, so mistakes here change the logic of the whole program.

What is operator precedence?

The rule that decides the order in which operators are applied, such as multiplication before addition, and parentheses override it.

Why is equality testing risky with floats?

Floating-point values have rounding errors, so comparing for exact equality often fails, and a tolerance is usually better.

How is Operators and expressions used in practice?

Typical applications include computing a total price with arithmetic operators, checking that a value is within a range with comparison operators and combining two conditions for an access rule with logical operators.

What should I learn before Operators and expressions?

Study "Variables and data types" first (topic 3 of 104 in Software & Computing). It covers the groundwork this topic builds on.

What are the key points of Operators and expressions?

Short-circuit evaluation. Modulo for cyclic behaviour. Beware = vs ==.

Can you give an example of Operators and expressions?

7 // 2 is 3 and 7 % 2 is 1 in Python.

What comes after Operators and expressions?

The next topic is "Control flow", which builds directly on this one.

How difficult is Operators and expressions?

It is classed as Beginner in Software & Computing (topic 4 of 104). It is an entry-level topic. It relies only on basic school mathematics and the ideas introduced earlier in this discipline.

Learning path

Want to practise? Open the interactive course for quick checks, quizzes, simulations and progress tracking.

Related topics