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+=3increments the value ofaby 3, and is equivalent to the statementa=a+3.- -
= Used to decrement a variable’s value. For example,
a-=3decrements the value ofaby 3, and is equivalent to the statementa= a-3.-
*= Used to multiply a variable’s value by a specified value. For example,
a*=3causes the variableato 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/=3causes the variableato 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%=3causes the variableato be assigned a value that is equal to the remainder of the operationa/3, and is equivalent to the statementa=a%3.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access