TL DR: expressions are combinations of values ​​and operators and are always evaluated to a single value. A statement is any other instruction. Some statements contain expressions.
expression is a command that combines values ​​and operators and always evaluates to a single value.
For example, this expression:
>>> 2 + 2
2s are integer values, and + is a mathematical operator. This expression evaluates to a single integer value of 4.
Technically, this is also an expression:
>>> 4
As an expression, it is evaluated to a single value of 4.
When I say values ​​and operators, this is not limited to mathematical problems:
>>> 'You will be ' + str(int(myAge) + 1) + ' next year.'
The variable myAge evaluates the value inside it. The function call int('5') corresponds to the return value of the function, 5 . All these string values ​​are combined with the + operator (in this case, the string concatenation operator). No matter how large the expression, it evaluates to single : in this case, the string value 'You will be 6 next year.'
Compare this with the operator , which is a Python statement that does not evaluate a value to a value. The Python operator is almost everything that is not an expression. Here's the assignment operator:
>>> spam = 2 + 2
Here's the if statement:
>>> if spam == 4:
Here's the while statement for an infinite loop:
>>> while True:
Note that both of these statements contain expressions (even True , which evaluate to a single value of True ). But not all statements use expressions in them. Here's the break statement:
>>> break