title: Why is 'new_file += line + string' so much faster than 'new_file = new_file + line + string'?
body: <p>Our code takes 10 minutes to siphon thru 68,000 records when we use:</p>
  
  <pre><code>new_file = new_file + line + string
  </code></pre>
  
  <p>However when we do the following it takes just 1 second:</p>
  
  <pre><code>new_file += line + string
  </code></pre>
  
  <p>Here is the code:</p>
  
  <pre><code>for line in content:
  import time
  import cmdbre
  
  fname = "STAGE050.csv"
  regions = cmdbre.regions
  start_time = time.time()
  with open(fname) as f:
          content = f.readlines()
          new_file_content = ""
          new_file = open("CMDB_STAGE060.csv", "w")
          row_region = ""
          i = 0
          for line in content:
                  if (i==0):
                          new_file_content = line.strip() + "~region" + "\n"
                  else:
                          country = line.split("~")[13]
                          try:
                                  row_region = regions[country]
                          except KeyError:
                                  row_region = "Undetermined"
                          new_file_content += line.strip() + "~" + row_region + "\n"
                  print (row_region)
                  i = i + 1
          new_file.write(new_file_content)
          new_file.close()
          end_time = time.time()
          print("total time: " + str(end_time - start_time))
  </code></pre>
  
  <p>All code I've ever written in python uses the first option. This is just basic string operations... we are reading input from a file, processing it and outputting it to the new file. I am 100% certain that the first method takes roughly 600 times longer to run than the second, but why?</p>
  
  <p>The file being processed is a csv but uses ~ instead of a comma. All we are doing here is taking this csv, which has a column for country, and adding a column for the countries region, e.g. LAC, EMEA, NA, etc... cmdbre.regions is just a dictionary, with all ~200 countries as the key and each region as the value.</p>
  
  <p>Once I changed to the append string operation... the loop completed in 1 second instead of 10 minutes... 68,000 records in the csv.</p>