September 2026
1051 pages
35h 4m
English
In Python 3.8, assignment expressions were introduced. These are understood to be hybrids between an assignment and an expression that evaluates to the assignment value. In the following example, we’ll determine the square of an integer y in terms of a simple arithmetic expression:
>>> y = 10>>> y*y100
Here, the interactive mode helps us capture the value of the expression y*y. For example, such an expression can be used in the context of a conditional statement, where its value becomes part of a larger logical expression:
>>> if y*y >= 100:... print("Yeah!")... Yeah!
An assignment assigns a name to the value of an expression, which can be used to reference it later in the program. Unlike an expression, an assignment ...
Read now
Unlock full access