Make Python create a tuple with one element in a clean way
alex23
wuwei23 at gmail.com
Sun May 11 09:50:13 EDT 2008
On May 11, 10:54 pm, wxPytho... at gmail.com wrote:
> I thought that just putting a value inside ( )
> would make a tuple. Apparently that is not the case.
It's not the case at all. Check out the Tuples & Sequences section in
the python docs at http://docs.python.org/tut/node7:
"A tuple consists of a number of values separated by commas"
So it's not the parentheses that define it as a tuple, but the comma.
>>> my_tuple = 1,
>>> my_tuple
(1,)
>>> type(my_tuple)
<type 'tuple'>
Hope this helps.
- alex23
More information about the Python-list
mailing list