Assignment Operators
Here are the common assignment operators:
-
=
Used to assign a value to a variable.
-
+=
Used to increment a variable’s value. For example,
a
+=
3
increments the value ofa
by 3, and is equivalent to the statementa
=
a
+
3
.- -
=
Used to decrement a variable’s value. For example,
a
-=3
decrements the value ofa
by 3, and is equivalent to the statementa
= a
-
3
.-
*=
Used to multiply a variable’s value by a specified value. For example,
a
*=
3
causes the variablea
to be assigned a value equal to itself multiplied by 3, and is equivalent to the statementa
=
a
*
3
.-
/=
Used to divide a variable’s value by a specified value. For example,
a
/=3
causes the variablea
to be assigned a value equal to itself divided by 3, and is equivalent to the statementa
=
a
/
3
.-
%=
Used to assign a variable a value equal to the remainder of a division operation between itself and a specified value. For example,
a
%=3
causes the variablea
to be assigned a value that is equal to the remainder of the operationa/3
, and is equivalent to the statementa
=
a
%
3
.
Get Network Security Tools now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.