Why is variable1 += variable2 much faster than variable1 = variable1 + variable2?
问题 I have inherited some Python code which is used to create huge tables (of up to 19 columns wide by 5000 rows). It took nine seconds for the table to be drawn on the screen. I noticed that each row was added using this code: sTable = sTable + \'\\n\' + GetRow() where sTable is a string. I changed that to: sTable += \'\\n\' + GetRow() and I noticed that the table now appeared in six seconds . And then I changed it to: sTable += \'\\n%s\' % GetRow() based on these Python performance tips (still