[1,2,3] exactly same as [1,2,3,] ?
Roy Smith
roy at panix.com
Fri Aug 29 11:11:41 EDT 2008
In article <QOCdnfa_yarxliXVnZ2dnUVZ_i2dnZ2d at posted.visi>,
Grant Edwards <grante at visi.com> wrote:
> On 2008-08-29, Roy Smith <roy at panix.com> wrote:
>
> > Exactly. This is one of those little pieces of syntactic
> > sugar which makes python so nice to work with. The
> > alternative is (in C, for example) abominations like this:
> >
> > const char* l[] = {"foo"
> > , "bar"
> > , "baz"
> > };
> >
> > and even those are not quite as good because you still have to
> > special-case the first entry.
>
> It's probably a spec violation, but I've never seen a C
> compiler that objected to a comma after the last item in an
> initializer list. (At least not at the warning levels I use,
> which tend to be on the picky side.)
Yowza, you're right (at least for the one case I tried). This must be a
new development (where "new development" is defined as, "It wasn't legal in
the original K&R C I learned when I was a pup").
Still, I have seem people do that in code.
More information about the Python-list
mailing list