LESSON 2

PAGE 1 / 4

Expressions
To perform calculations, programs use expressions. You have already used them in the first lesson!Definition 1. An expression is a sequence of one or more operands, linked together by operators, according to programming languagespecific syntactic rules.
For example, for the expression 3 + 4 * 2
3, 4 and 2 are operands, and + and * are operators.
An incorrectly written expression will lead to an interpretation error (this is called a syntax error):
During the execution of the Python program, the expressions are evaluated (i.e. a result is calculated).
Arithmetic operators can be unary or binary.
Unary operators
Unary operators (+ and ) act on a single operand that is always to the right of the operator. "+" returns the value of the operand, and "" returns the value of the changed sign operand.Examples: 23, +11
Binary operators
Binary operators (+, , *, /, //, %) act on two operands. One operand is always to the left of the operator and the other to his right.Examples: 10+5, 52, 7*5, etc.
We analyze some peculiarities of three operators on the next page.
These notions are very important!
If you have finished reading, go to the next page.
If you have finished reading, go to the next page.
home  list LESSONS  arrow_upward 