title: What is the correct format to write float value to file in Python
body: <p>I have a bunch of float values, for example:</p>
  
  <p>x1 = 1.11111111</p>
  
  <p>x2 = 2.22222222</p>
  
  <p>I want to write these values to a file:</p>
  
  <pre><code>f = open("a.dat", "w+")
  f.write("This is x1: ",x1)
  f.write("\n")              #I want to separate the 2 lines
  f.write("This is x2: ",x2)
  </code></pre>
  
  <p>At this point I got an error on the second line:</p>
  
  <pre><code>write() takes exactly one argument (2 given)
  </code></pre>
  
  <p>How do I write to file such that when I open it, I see this format:</p>
  
  <pre><code>This is x1: 1,1111111
  This is x2: 2,2222222
  </code></pre>
  
  <p>And yes, the file has to be ***.dat</p>
  
  <p>It's not .txt</p>