| Re: Make Python create a tuple with one element in a clean way |
|
 |
|
 |
|
 |
|
 |
Group: comp.lang.python · Group Profile
Author: Asun FriereAsun Friere Date: May 11, 2008 18:37
On May 11, 10:54 pm, wxPytho...@ gmail.com wrote:
> To create a tuple with one element, you need to do this:
>
>>>> my_tuple = (1,) # Note the trailing comma after the value 1
>>>> type(my_tuple)
>
>
>
You needn't at all. You could simply do this:
>>> your_tuple = 1,
You see, it's not the parentheses that make the tuple.
> But if you do this
>
>>>> my_tuple = (1)
>>>> type(my_tuple)
>
>
>
> you don't get a tuple.
For which the BDFL should make us eternally grateful.
> it would be clean if Python would convert anything put into ( ) to
> be a tuple
You seriously want 2*(3+4) to return (7,7)? You call that "clean"?!
At least type(my_tuple) would always return 'tuple,' whether it was or
not. ;)
|