How to force a single number to be a tuple

Gandalf gandalf at geochemsource.com
Wed Aug 4 13:37:36 EDT 2004



Peter Otten wrote:

>  File "<stdin>", line 1
>    () == (,)
>           ^
>SyntaxError: invalid syntax
>
I said this:

"Try to add one comma for each element - that will do the stuff."

How many elements do you want?
For zero elements, you should add zero commas. ;-)

>  
>
>>>>(1) == (1,)
>>>>        
>>>>
>False
>
Of course. The first one is not a tuple.

>  
>
>>>>(1, 2) == (1, 2,)
>>>>        
>>>>
>True
>
Yes, because you can omit the last comma if there is at least one element.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20040804/de1d976b/attachment.html>


More information about the Python-list mailing list