Jeff R. Allen wrote:

a, b = 0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable

I understand why it doesn't work, but I don't understand the wording
of the exception. Could someone explain how I accidentally introduced
iteration into the picture with my syntax? I have a feeling there's an
interesting lesson hidden in this example...

To upack your variables a and b you need an iterable object on the right side, which returns you exactly 2 variables, e.g you could also write

a, b = range(2)

or create your own class

class X:
        def __iter__(self):
                yield 0
                yield 0

a,b = X()

- Patrick
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to