LambdaLabTM
Computer Science · Class 11 · Expressions & Operators
ExpressionsBasics⏱️ 8 min read

Expressions, Operands & Operators

You have already typed print(2 + 3) and seen Python answer 5. That 2 + 3 has a name. It is called an expression. Every expression is made of just two kinds of parts.

1Three words to learn

Look at 2 + 3. It has two values — 2 and 3 — and one symbol between them, the +. Each of these has a name in Python.

Operands

The values on which the work is done. In 2 + 3, the operands are 2 and 3.

Operators

The symbols that tell Python what to do with the operands. In 2 + 3, the operator is +.

Expression

Operands and operators together. Python solves an expression and gets one single value from it.

Key Takeaway
Expression = operands + operators. The operands are the values. The operators are the symbols that say what to do with those values.

2A longer example: 2 + 3 - 4

An expression can have more than one operator and more than two values. Look at 2 + 3 - 4:

2operand
+operator
3operand
-operator
4operand

2, 3 and 4 are the operands · + and - are the operators

Three operands, two operators, one expression. However long an expression is, Python does the same thing with it. It solves the expression and puts the one value it gets in its place.

Python prompt — interactive mode
>>> print(2 + 3 - 4)
1
>>> print(4 + 10 * 5)
54
Why 54, and not 70?
In 4 + 10 * 5, Python does the * before the +. This is the same rule you follow in maths — multiply first, then add. The rule that decides which operator is done first is called precedence. It has its own lesson at the end of this chapter.

3Take one apart

Click each expression below. The operands are shown in purple and the operators in black. Below them you can see the one value that Python gets from the whole expression.

Pick an expression — see what it is made of
2operand
+operator
3operand
Python solves it into one value
5

Two operands and one operator. This is the smallest expression you can write.

2 operands — the values1 operator — what to do with the values
Note
See the last two. An expression need not be a sum. 12 > 3 asks a question, and its value is True. 'py' + 'thon' joins two strings, and its value is 'python'. The idea is the same. Only the operators are different.

4An expression becomes one value

Remember this. Python never prints the expression itself. It solves the expression first, and only the answer is given to print().

Python prompt — interactive mode
>>> print(2 + 3) # 2 + 3 becomes 5, and 5 is printed
5
>>> print('2 + 3') # inside quotes it is text — nothing is solved
2 + 3

The answer of an expression is a value, so it has a type too. 2 + 3 gives an int. 10 / 4 gives a float. 12 > 3 gives a bool. You will learn about each of them in the next three lessons.

5There is no × on your keyboard

In your maths notebook you write 2 × 3. Python does not understand ×. For multiplication it uses the asterisk, *:

Python prompt — interactive mode
>>> print(2 * 3)
6

Every Python operator can be typed using the keys on your keyboard. Now try some expressions of your own:

Python prompt — interactive mode
# Type an expression and press Enter. Python solves it and shows the answer.
>>>
try

6Recap

Key Takeaway
An expression is made of operands (the values) and operators (the symbols that tell Python what to do with them). Python solves the whole expression and replaces it with one single value.
Quick Check

In the expression 2 + 3 - 4, which are the operands?

Quick Check

In the expression 4 + 10 * 5, which are the operators?

Quick Check

How many values does Python get from one expression?