In both examples, hi = original_string copies the link.
With += , however, you reassign hi to point to a new line, although the variable name is the same.
This is due to the fact that hi += there expands in the interpreter to the expression hi = hi + there .
Prior to this operation, hi and original string use a link to the same string object. After the = operation, in the extended expression, hi now refers to the newly created result of the string hi + there .
In the expression hi << there will not change anything to which object hi belongs. It refers to the same string as original_string , and therefore both hi and original_string reflect the change (which, of course, is due to the fact that both of them refer to the same string object).
source share