Indexing Into A Tuple

Tim Daneliuk tundra at tundraware.com
Wed Jun 27 18:39:25 CEST 2001


Hmm, it works, but I don't understand why.  I have a tuple of tuples
defined as follows:

MyTuple = ( ("a", "b"), ("c", "d")...)

Now, I want to iterate across it to print the pairs.  This works as I
would expect:

for x in MyTuple:
        print x[0], x[1]

But so does this:

for x, y in MyTuple:
        print x, y

Intuitively (and, obviously, incorrectly) it seems to me that the 1st
time through, the second example should return:

      x=("a", "b") and y=("c", "d")

Instead, it returns x="a", and y="b" just like the first example.

Why?
-- 
------------------------------------------------------------------------------
Tim Daneliuk
tundra at tundraware.com



More information about the Python-list mailing list