On 23/05/2018 14:11, Steven D'Aprano wrote:
On Wed, 23 May 2018 11:10:33 +0100, bartc wrote:
(x,)  Tuple of one item

Incorrect. Yet again, you have failed to do enough testing. No special
form is required. Only a comma:

py> x = 1,
py> type(x)
<class 'tuple'>

It isn't enough to test examples which confirm a hypothesis. You need to
test examples which also refute it, and see if your hypothesis survives
the challenge.

I use this trailing comma scheme in my own own languages too. The reason is simple, it is to distinguish between these two:

  (x)     Ordinary bracketed expression
  (x)     A list (in my case) of one item.

That is not needed for one less item: (), or one more: (x,y). Like Python, that trailing comma is not needed for [x] (I don't have a {...} constructor).

In both languages, it's just a hack to get around a syntax clash in the language.

I don't say however, that the comma is the defining feature of a list.

Comma is used to separate items of /any/ kind of list, and that trailing comma is used when there is an ambiguity or a conflict.

--
bartc
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to