title: When to use == and when to use is?
body: <p>Curiously:</p>
  
  <pre><code>&gt;&gt;&gt; a = 123
  &gt;&gt;&gt; b = 123
  &gt;&gt;&gt; a is b
  True
  &gt;&gt;&gt; a = 123.
  &gt;&gt;&gt; b = 123.
  &gt;&gt;&gt; a is b
  False
  </code></pre>
  
  <p>Seems <code>a is b</code> being more or less defined as <code>id(a) == id(b)</code>.  It is easy to make bugs this way:</p>
  
  <pre><code>basename, ext = os.path.splitext(fname)
  if ext is '.mp3':
      # do something
  else:
      # do something else
  </code></pre>
  
  <p>Some fnames unexpectedly ended up in the else block.  The fix is simple, we  should use <code>ext == '.mp3'</code> instead, but nonetheless <code>if ext is '.mp3'</code> on the surface seems like a nice pythonic way to write this and it's more readable than the "correct" way.  </p>
  
  <p>Since strings are immutable, what are the technical details of why it's wrong?  When is an identity check better, and when is an equality check better?</p>