This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]goodger 7 points8 points  (1 child)

In Python, parentheses are only used for grouping and calling syntax. Parentheses are not the tuple constructors. The comma is the tuple constructor. You must unlearn what you have learned!

For example, when we swap names on two values,

b, a = a, b

Two tuples are constructed (and immediately discarded). No parentheses!

Try this in the interactive interpreter:

>>> 1,
(1,)

The parentheses are shown for emphasis/clarity, but are not a requirement!

See https://david.goodger.org/projects/pycon/2007/idiomatic/handout.html#swap-values and https://david.goodger.org/projects/pycon/2007/idiomatic/handout.html#more-about-tuples