An immutable string cannot have its character data edited after creation. Operations that appear to change it, such as +=, instead create a new string containing the requested content. section 2.4.1
This behavior can become expensive when repeatedly extending a string. Adding one character in a ten-million-iteration loop creates ten million allocations and copies nearly all existing data each time. section 2.4.1
Repeated concatenation
The Python loop starts with an empty string, appends a dot ten million times, and prints the length. Its externally visible result is simple, but its immutable-string behavior repeatedly copies the accumulated value. section 2.4.1
Rust contrasts this with a mutable, growable String whose heap buffer has a length and capacity. Appending usually changes the existing buffer; allocation and copying occur when the new length exceeds capacity. section 2.4.1
