trying to understand why a tuple is preferred over a list for a specific python example (from a tutorial)
<p>I'm trying to learn what iterators and generators are in python, going through a tutorial i found online which used this fibonacci iterator as an example.  I'm having trouble with the comment on lines 9-11.  What does it mean that "the old values of self.fn1 and self.nf2 are used in assigning the new value"? I understand that tuples are immutable objects but i'm failing to see here why using tuple is preferred over a list. I guess I'm failing to see why using a tuple here is better than using a list and I would like to understand better if anyone can help explain it :/</p>

<pre><code>4 class fibnum:
5     def __init__(self):
6       self.fn2 = 1 # "f_{n-2}"
7       self.fn1 = 1 # "f_{n-1}"
8     def next(self): # next() is the heart of any iterator
9       # note the use of the following tuple to not only save lines of
10      # code but also to insure that only the old values of self.fn1 and
11      # self.fn2 are used in assigning the new values
12      (self.fn1,self.fn2,oldfn2) = (self.fn1+self.fn2,self.fn1,self.fn2)
13      return oldfn2
14    def __iter__(self):
15      return self
</code></pre>

<p>from : <a href="http://heather.cs.ucdavis.edu/~matloff/Python/PyIterGen.pdf" rel="nofollow">http://heather.cs.ucdavis.edu/~matloff/Python/PyIterGen.pdf</a></p>
