Python str = str + value is slow

42 views Asked by At

I am writing 2 Mbyte file line by line and using string variable to populate the data line by line first

When i did in loops str = str + new_data it took couple seconds to process the script.

Once i changed to str += new data script finishes instantly.

Though += was a shortcut for same command they added in newer versions.

Why first syntax causes substantially more time to process?

P.S. When i needed to write 50 MByte file script was never finishing in minutes, i suspect that was a reason.

0

There are 0 answers