Explanation for trailing comma in example from Learning Python?

Carl Schumann schumann at fnal.gov
Thu Feb 19 20:47:09 CET 2009


Hi,

I am surprised at the trailing comma in the following example from 
"Learning Python":
> Python 2.3.4 (#1, Dec 10 2007, 15:05:56)
> [GCC 3.4.5 20051201 (Red Hat 3.4.5-2)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> def f(*args): print args
> ...
> >>> f()
> ()
> >>> f(1)
> (1,)
> >>> f(1,2)
> (1, 2)
> >>> f(1,2,3)
> (1, 2, 3)
> >>> f(1,2,3,4)
> (1, 2, 3, 4)
> >>>
I could see the logic in always or never having a trailing comma.   What 
I don't understand here is why only the single element case has a 
trailing comma.   Any explanations please?

Thanks,
Carl Schumann





More information about the Python-list mailing list