one-element tuples

Ben Finney ben+python at benfinney.id.au
Mon Apr 11 01:40:38 EDT 2016


Fillmore <fillmore_remove at hotmail.com> writes:

> I thought I had made the point clear with the REPL session below. I
> had (what seemed to me like) a list of strings getting turned into a
> tuple. I was surprised that a single string wasn't turned into a
> single-element tuple.

Sure. What about the corresponding one from my example:

    >>> a = "string1"
    >>> b = "string1", "string2"
    >>> c = "string1", "string2", "string3"

    >>> type(a)
    <class 'str'>
    >>> type(b)
    <class 'tuple'>
    >>> type(c)
    <class 'tuple'>

Isn't that just as surprising as the same expressions evaluated with
‘eval’?

If not, that's what is confusing me. I can't see how one would be
expected, but the other would be surprising.

-- 
 \          “It is well to remember that the entire universe, with one |
  `\   trifling exception, is composed of others.” —John Andrew Holmes |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list