title: Checking objects reference equality in Python seems incoherent
body: <p>I'm trying to understand what happens with assignment and the creation of new references to an object, or why I get a new created object when assigning.</p>
  
  <p>I can't get my head on how <em>Python</em> and/or <em>Sublime</em> work here.
  I have this simple <em>Sublime</em> plugin:</p>
  
  <pre><code>import sublime
  import sublime_plugin
  
  class TestpythonCommand(sublime_plugin.TextCommand):
      def run(self, edit):
          view = self.view
          sel = view.sel()
          sel_zero = sel[0];
          sel_for = []
          for r in sel:
              sel_for.append(r)
          sel_gen = [r for r in view.sel()]
  
          print('SEL =&gt; ' + str(sel[0].a) +':' + str(sel[0].b) + ' ID: ' + str(id(sel[0])))
          print(str(id(sel[0])) + ' .. ' + str(id(sel[0])) + ' .. access A value: ' + str(sel[0].a) + ' .. ' + str(id(sel[0])))
          print('SEL[0] id is ' + str(id(sel[0])))
          print('SEL_ZERO =&gt; ' + str(sel_zero.a) +':' + str(sel_zero.b) + ' ID: ' + str(id(sel_zero)))
          print('SEL_FOR =&gt; ' + str(sel_for[0].a) +':' + str(sel_for[0].b) + ' ID: ' + str(id(sel_for[0])))
          print('SEL_GEN =&gt; ' + str(sel_gen[0].a) +':' + str(sel_gen[0].b) + ' ID: ' + str(id(sel_gen[0])))
          print('----- Test with self')
          print(id(sel[0]) == id(sel[0]))
          print(sel[0] is sel[0])
          print(sel[0] == sel[0])
          print('----- Test with list &amp; generator function')
          print(sel[0] is sel_zero)
          print(sel[0] == sel_zero)
          print(sel[0] is sel_for[0])
          print(sel[0] == sel_for[0])
          print(sel[0] is sel_gen[0])
          print(sel[0] == sel_gen[0])
  </code></pre>
  
  <p>Executing this returns:</p>
  
  <pre><code>SEL =&gt; 657:657 ID: 4378999048
  4378998328 .. 4378998328 .. access A value: 657 .. 4378998328
  SEL[0] id is 4378998328
  SEL_ZERO =&gt; 657:657 ID: 4379000488
  SEL_FOR =&gt; 657:657 ID: 4378996816
  SEL_GEN =&gt; 657:657 ID: 4378998760
  ----- Test with self
  True
  False
  True
  ----- Test with list &amp; generator function
  False
  True
  False
  True
  False
  True
  </code></pre>
  
  <p>Now, too many things don't make sense to me here:</p>
  
  <ol>
  <li>First print shows <code>sel[0]</code> <em>id</em> to be <strong>4378999048</strong>, but printing it again gives another <em>id</em> (<strong>4378998328</strong>)</li>
  <li>Third print does the same; looks the <em>id</em> printed in the first line is lost/changed/unused.</li>
  <li>First <em>"Test with self"</em> print makes sense (comparison of id strings is True); but I can't get the sense of the second print, using <code>is</code> (why <code>sel[0] is not sel[0]</code>?).</li>
  </ol>
  
  <p>I am trying to understand how stuff works here. Specifically, the purpose is to understand why I get new objects (instead of having a new reference to the same object) when using the generator-expression with <code>for</code>.</p>
  
  <p>I use <strong>SublimeText3</strong> and <strong>Python 2.7.10</strong>.</p>
  
  <p><strong>EDIT:</strong> I'd be interested in the best practice for checking <em>reference equality</em>, without using <code>is</code> (that <a href="https://stackoverflow.com/a/1085656/3088045">seems to be inconsistent, depending on implementation and caching</a>).</p>