title: Explain the difference between single-line assignment of integer x, item in list[x], and single-line assignments of inter-referencing variables
body: <p><em>I believe I answered my own question while trying to figure out how to ask it properly, but since I found the answer in <a href="https://docs.python.org/3/reference/simple_stmts.html#assignment-statements" rel="nofollow noreferrer">Python's documentation</a> to be rather opaque, I thought I'd still post the question here.</em></p>
  
  <p>While trying to understand the rules of single-line assignments in Python, I came across some examples that contradict the usual statement that "single-line assignments to multiple variables all take place at once".</p>
  
  <pre><code>a = 0 # variable 'a' must be assigned first
  
  a, b = 1, a # a, b :: 1, 0
  
  x = [2, 3, 4, 5, 6]
  
  i, x[i] = 4, 99 # i, x[4] :: 4, 99; variable 'i' does not need to have been previously assigned
  
  c = 8 # variable 'c' must be assigned first
  
  c, d = 9, print(c) # c, d :: 9, None; prints 8
  </code></pre>
  
  <p>My confusion had to do with the fact that Python reassigned <code>'i'</code> (i.e., the list index) first, before assigning 99 to index 4 of list <code>'x'</code>.</p>
  
  <p>While Python's documentation directly addresses this issue as following,</p>
  
  <blockquote>
    <p>Although the definition of assignment implies that overlaps between
    the left-hand side and the right-hand side are ‘simultaneous’ (for
    example a, b = b, a swaps two variables), overlaps within the
    collection of assigned-to variables occur left-to-right, sometimes
    resulting in confusion.</p>
  </blockquote>
  
  <p>I did not understand what it meant by "overlaps within the collection of assigned-to variables".</p>
  
  <p>I see now that the parser will check to see if the indexing value for a given List has been reassigned before it assigns a new value to that index of the list.</p>
  
  <hr>
  
  <h2>Notes:</h2>
  
  <p>This is confirmed by the fact that, in this case, <code>'i'</code> did not need to be assigned first before it was used as a variable index, while for <code>'a'</code> it was necessary (otherwise, Python would throw an error).</p>
  
  <p>For those curious, here's the <a href="http://pythontutor.com/visualize.html#code=a%20%3D%200%20%23%20variable%20&#39;a&#39;%20must%20be%20assigned%20first%0A%0Aa,%20b%20%3D%201,%20a%20%23%20a,%20b%20%3A%3A%201,%200%0A%0Ax%20%3D%20%5B2,%203,%204,%205,%206%5D%0A%0Ai,%20x%5Bi%5D%20%3D%204,%2099%20%23%20i,%20x%5B4%5D%20%3A%3A%204,%2099%0A%0Ac%20%3D%208%20%23%20variable%20&#39;c&#39;%20must%20be%20assigned%20first%0A%0Ac,%20d%20%3D%209,%20print%28c%29%20%23%20c,%20d%20%3A%3A%209,%20None%3B%20prints%208&amp;cumulative=false&amp;curInstr=6&amp;heapPrimitives=false&amp;mode=display&amp;origin=opt-frontend.js&amp;py=3&amp;rawInputLstJSON=%5B%5D&amp;textReferences=false" rel="nofollow noreferrer">PythonTutor visualization</a>. Unfortunately, because it executes the assignment in one line (<em>as it should</em>), one cannot really see how Python interprets the statement.</p>
  
  <p>This opacity of execution would be further compounded in the case of a user who had previously assigned i to an integer, and intended to use that previous integer as an index, and not the new value.</p>
  
  <hr>
  
  <p><em>By the way, this is my first time asking a question, so I don't have the necessary reputation to post my own answer. Please feel free to provide any constructive advice on how I can improve any future questions I may ask, or on how I might better contribute to this community. Thanks.</em></p>