Self-assignment operator

Self-assignment operator (+ =,-=, * =, / =)

** Self-assignment, as the name implies, means assigning to yourself. The self-assignment operator can be described by omitting the writing method using the usual operator. ** **

As an example, let's change number = number + 1 </ font> to the self-assignment operator + = </ font>.

[Example] Normal assignment operator


number = number + 1

You can rewrite this expression as follows by using the self-assignment operator + = </ font>. These have the same meaning.

[Example] Self-assignment operator


number += 1

As you can see by comparing the above source code, the expression number + = 1 </ font> using the self-assignment operator becomes the variable number </ font>. Substitute the value obtained by adding 1 to number </ font> itself It will be the process. The typical self-assignment operators are shown below.

自己.png

By using the self-assignment operator in this way, you can add the value of the variable itself, You can easily describe pulling.

It is often used because the code can be omitted. Remember both statements.

Summary

** Because you can omit the code by using the self-assignment operator You can make it easier to read and write. ** **

that's all.