Chapter 7. Simple statements 86 The Python Language Reference, Release 3.9.5 7.2.1 Augmented assignment statements Augmented assignment is the combination, in a single statement, of a binary operation and an assignment statement: (See section Primaries for the syntax definitions of the last three symbols.) An augmented assignment evaluates the target (which, unlike normal assignment statements, cannot be an unpacking) and the expression list, performs the binary operation specific to the type of assignment on the two operands, and assigns the result to the original target. The target is only evaluated once. An augmented assignment expression like$_{x += 1}$ can be rewritten as$_{x = x + 1}$ to achieve a similar, but not exactly equal effect. In the augmented version, x is only evaluated once. Also, when possible, the actual operation is performed in-place , meaning that rather than creating a new object and assigning that to the target, the old object is modified instead. Unlike normal assignments, augmented assignments evaluate the left-hand side before evaluating the right-hand side. For example, a[i] += f(x) first looks-up a[i] , then it evaluates f(x) and performs the addition, and lastly, it writes the result back to$_{a[i]}$ . With the exception of assigning to tuples and multiple targets in a single statement, the assignment done by augmented assignment statements is handled the same way as normal assignments. Similarly, with the exception of the possible in- place behavior, the binary operation performed by augmented assignment is the same as the normal binary operations. For targets which are attribute references, the same caveat about class and instance attributes applies as for regular assignments. Annotation assignment is the combination, in a single statement, of a variable or attribute annotation and an optional assignment statement: The difference from normal Assignment statements is that only single target is allowed. For simple names as assignment targets, if in class or module scope, the annotations are evaluated and stored in a special class or module attribute$_{__annotations__}$ that is a dictionary mapping from variable names (mangled if private) to evaluated annotations. This attribute is writable and is automatically created at the start of class or module body execution, if annotations are found statically. For expressions as assignment targets, the annotations are evaluated if in class or module scope, but not stored. If a name is annotated in a function scope, then this name is local for that scope. Annotations are never evaluated and stored in function scopes. If the right hand side is present, an annotated assignment performs the actual assignment before evaluating annotations (where applicable). If the right hand side is not present for an expression target, then the interpreter evaluates the target except for the last$_{__setitem__()}$ or$_{__setattr__()}$ call. See also: PEP 526 - Syntax for Variable Annotations The proposal that added syntax for annotating the types of variables (including class variables and instance variables), instead of expressing them through comments. PEP 484 - Type hints The proposal that added the$_{typing}$module to provide a standard syntax for type annota- 7.2.2 Annotated assignment statements annotated_assignment_stmt ::= augtarget ":" expression ["=" ( starred_expression | yield_expression )] augmented_assignment_stmt ::= augtargetaugop ( expression_list | yield_expression ) augtarget ::= identifier | attributeref | subscription | slicing augop ::= | ">>=" | "<<=" | "&=" | "^=" | "|="