Shortcut Operators Flashcards
1
Q
Shortcut operators
It’s time for the next set of operators that make a developer’s life easier.
A
Very often, we want to use one and the same variable both to the right and left sides of the = operator.
2
Q
If op is a two-argument operator (this is a very important condition) and the operator is used in the following context:
A
variable = variable op expression
t can be simplified and shown as follows:
variable op= expression
3
Q
i = i + 2 * j
A
⇒ i += 2 * j
4
Q
var = var / 2
A
⇒ var /= 2
5
Q
rem = rem % 10
A
⇒ rem %= 10
6
Q
j = j - (i + var + rem)
A
⇒ j -= (i + var + rem)
7
Q
x = x ** 2
A
⇒ x **= 2