[1,2,3] exactly same as [1,2,3,] ?

Roy Smith roy at panix.com
Fri Aug 29 16:15:06 CEST 2008


Terry Reedy <tjreedy at udel.edu> wrote:
> Yes, so you can write something like either your second example or
> 
> l = [
>    kjasldfjs,
>    kjsalfj,
>    ksjdflasj,
> ]
> 
> and insert items without worrying about leaving out the comma (less of a 
> problem with 'horizontal' list), or delete the last line and not have to 
> worry about deleting the comma on the line before.

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.



More information about the Python-list mailing list