[Python-ideas] Python Users Aren't Perfect
Ned Batchelder
ned at nedbatchelder.com
Mon Dec 12 14:26:16 CET 2011
On 12/12/2011 8:19 AM, Antoine Pitrou wrote:
> Le lundi 12 décembre 2011 à 08:15 -0500, Ned Batchelder a écrit :
>> Believe me, I understand the issues. It is true, though that the
>> single-element tuple syntax is often a surprise to people, and often
>> well into their Python learning experience. We often repeat, "it isn't
>> parens that make a tuple, but a comma." Then why when displaying a
>> tuple does Python insist on using parens around it?
>>
>> >>> 1, 2, 3
>> (1, 2, 3)
> I would say:
> - because it's easier to read (subjectively so, I guess)
> - because it's easier to copy/paste into an expression without running
> into precedence problems
Yes, those are good reasons. And you can see why Python's insistence on
showing tuples with parens contributes to the gotcha that the parens are
a red herring, and it's the commas that are important. Also, who hasn't
said this to a beginner: "lists and tuples are very similar, lists use
square brackets, tuples use parens"? Somehow, in a list, the commas
don't make a tuple... It's complicated.
I welcome Richard's help in explaining this issue to beginners.
--Ned.
> Regards
>
> Antoine.
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
More information about the Python-ideas
mailing list