[Python] Python subtleties

John Heasly jheasly at guardnet.com
Thu Sep 21 16:53:13 PDT 2006


1) is a string, 2), 3) and 4) are tuples.

Python has "magic" for making one-item tuples. See http:// 
www.python.org/doc/current/tut/node7.html#SECTION007300000000000000000:

" ... A special problem is the construction of tuples containing 0 or  
1 items: the syntax has some extra quirks to accommodate these. Empty  
tuples are constructed by an empty pair of parentheses; a tuple with  
one item is constructed by following a value with a comma (it is not  
sufficient to enclose a single value in parentheses). ... "

Cheers,
John

On Sep 21, 2006, at 4:41 PM, Rob Hudson wrote:

> In Python, what's the difference between these two:
>
> 1) var = ('val')
> 2) var = ('val',)
>
> Knowing that, is there a difference between these two?
>
> 3) var = ('val1', 'val2')
> 4) var = ('val1', 'val2',)
>
> -Rob
> _______________________________________________
> Python mailing list
> Python at euglug.org
> http://www.euglug.org/mailman/listinfo/python



More information about the Python mailing list