Explanation for trailing comma in example from Learning Python?
ma
mabdelkader at gmail.com
Thu Feb 19 16:01:55 EST 2009
A comma is what generates a tuple. It's not the parenthesis;)
http://docs.python.org/library/stdtypes.html#typesseq
"A single item tuple must have a trailing comma, such as (d,)."
On Thu, Feb 19, 2009 at 3:57 PM, alex goretoy
<aleksandr.goretoy at gmail.com>wrote:
> Thank you for clerification Christian,
> when using trailing comma with print statement/function, does it not mean
> to output newline after printed data?
>
> -Alex Goretoy
> http://www.goretoy.com
>
>
>
>
> On Thu, Feb 19, 2009 at 2:54 PM, Christian Heimes <lists at cheimes.de>wrote:
>
>> Carl Schumann wrote:
>> > 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?
>>
>> Does this code shad some light on the trailing comma? :)
>>
>> >>> (1) == 1
>> True
>> >>> (1,) == 1
>> False
>> >>> type((1))
>> <type 'int'>
>> >>> type((1,))
>> <type 'tuple'>
>>
>> >>> a = 1
>> >>> a
>> 1
>> >>> a = (1)
>> >>> a
>> 1
>> >>> a = (1,)
>> >>> a
>> (1,)
>> >>> a = 1,
>> >>> a
>> (1,)
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090219/4c069955/attachment-0001.html>
More information about the Python-list
mailing list