A new to Python question

Fredrik Lundh fredrik at pythonware.com
Sun May 15 02:00:47 EDT 2005


M.E.Farmer wrote:

> I said exactly what I meant, the parentheses around the values creates
> a tuple that you have no reference to!

repeating it doesn't make you right; no extra tuple is created, and the
parens are part of the syntax:

    If the target is a target list enclosed in parentheses or in square
    brackets: The object must be a sequence with the same number
    of items as there are targets in the target list, and its items are
    assigned, from left to right, to the corresponding targets.

    http://docs.python.org/ref/assignment.html

(originally, you had to use [] to unpack lists, and () or no parens only
worked for tuples.  the ability to use an arbitrary sequence was added
in 1.5)

on the other hand, the function you're calling in this example *does*
create a tuple that you have no reference to after the assignment.
that doesn't matter, of course, since the tuple is removed by the
garbage collector immediately after it has been unpacked.

</F>






More information about the Python-list mailing list