In the case of assigning, normal operators are there. Inplace operators are similar to normal operators, but they perform differently for mutable and immutable targets in python for data science.
Let us look into an example of an add operator.
- The _add_ method is in use when we perform a simple sum of two arguments and then store it in the form of a variable. In this method, modification of arguments does not take place.
- But _iadd_ method performs differently. It takes two arguments and makes in-place modification in the first argument pass storing the sum in it. Immutable targets should not have _iadd_ method as this method requires modification.
- The normal operator add() performs “a+b” and the resultant is store in the variable we have.
- “iadd()” method which is an inplace operator performs “a+=b” in case of mutable targets, and then the value of the pass argument is change. In the case of an immutable target “a+b” executes..
Note: In both cases above assignment is must to store the value.
In the case of immutable targets, there is no change in behavior for normal and inplace operators, both behave in a similar fashion. Only assignment is done, and no modification in the pass argument takes place.
In the case of mutable targets, the difference in inplace operators and normal operators can be seen. The modification and assignment both are done by inplace operators in mutable targets.