Extra comma

Harvey Thomas hst at empolis.co.uk
Wed Feb 12 09:52:50 EST 2003


Oren Tirosh wrote:
> On Thu, Feb 13, 2003 at 02:50:11AM +1300, Paul Foley wrote:
> > On Thu, 13 Feb 2003 01:29:42 +1300, Paul Foley wrote:
> > 
> > > On Wed, 12 Feb 2003 05:10:00 -0500, Oren Tirosh wrote:
> > >> There is a slight inconsistency in Python in that it 
> doesn't allow a
> > >> trailing comma in an empty list, tuple or argument list. 
> 1-tuples REQUIRE 
> > >> a comma and 0-tuples FORBID a comma. If would have been 
> more consistent
> > >> to always allow a trailing comma.
> > 
> > > That wouldn't even make /sense/, let alone being "more 
> consistent".
> > 
> > Hmm.  That didn't come out right.  In fact, it does make 
> sense, and it
> > /is/ allowed:
> > 
> >   1,
> >   1,2,
> >   1,2,3,
> > 
> > etc., are perfectly legal 1-, 2-, and 3-tuples.  You obviously can't
> > have a 0-tuple with a comma, though.
> 
> It would require parentheses, just like 0-tuples currently do:
> 
> (,)	<- currently not allowed, but could be.
> (1,)
> (1,2,)
> (1,2,3,)
> 
> ()
> (1)	<- not allowed, for obvious reasons.
> (1,2)
> (1,2,3)
> 
> I'm not actually proposing this as a language feature, just 
> pointing it
> out.
> 
> 	Oren

Minor curiosity:

>>> {1:1, 2:2,}
{1: 1, 2: 2}
but of course:

>>> {1:1, 2:(2,)}
{1: 1, 2: (2,)}

_____________________________________________________________________
This message has been checked for all known viruses by the MessageLabs Virus Scanning Service.





More information about the Python-list mailing list