one-element tuples

Ben Finney ben+python at benfinney.id.au
Sun Apr 10 21:36:58 EDT 2016


Fillmore <fillmore_remove at hotmail.com> writes:

> On 04/10/2016 08:31 PM, Ben Finney wrote:
> > Can you describe explicitly what that “discontinuation point” is? I'm
> > not seeing it.
>
> Here you go:
>
> >>> a = '"string1"'
> >>> b = '"string1","string2"'
> >>> c = '"string1","string2","string3"'
> >>> ea = eval(a)
> >>> eb = eval(b)
> >>> ec = eval(c)
> >>> type(ea)
> <class 'str'>   <--- HERE !!!!
> >>> type(eb)
> <class 'tuple'>
> >>> type(ec)
> <class 'tuple'>

While I wait to find out what confuses you about the above, let me ask
another question that might get closer to the issue.

Would you find the following session confusing? Why?

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

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

> and mind you, I am not saying that this is wrong. I'm just saying that
> it surprised me.

If the two examples give you different responses (one surprises you, the
other does not), I would really like to know *what the surprise is*.
What specifically did you expect, that did not happen?

-- 
 \        “I knew it was a shocking thing to say, but … no-one has the |
  `\        right to spend their life without being offended.” —Philip |
_o__)                                              Pullman, 2010-03-28 |
Ben Finney




More information about the Python-list mailing list