About Expressions
To perform calculations, programs use
expressions.
You've already used them in the first lesson!
Definition 1. An
expression is a sequence composed of one or more
operands, linked together by
operators, according to specific syntactic rules of the programming language.
For example, in the expression
3 + 4*2
3,
4, and
2 are operands, and
+ and
* are operators.
An incorrectly written expression will lead to a syntax error:
During the execution of the Python program, 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 located
to the right of the operator.
The "
+" operator returns the operand's value, while the "
-" operator returns the operand's value with the sign changed.
Examples:
-23,
+11
Binary Operators
Binary operators (
+,
-,
*,
/,
//, and
%) act on
two operands.
One operand is always on the
left of the operator, and the other is on the
right.
Examples:
10+5,
5-2,
7*5, etc.
We will further analyze some specific characteristics of three operators.
These concepts are very important!
If you have finished reading, proceed to the next page.