On Mon, Apr 11, 2016 at 10:13 AM, Fillmore <[email protected]> wrote:
> Sorry guys. It was not my intention to piss off anyone...just trying to
> understand how the languare works
>
> I guess that the answer to my question is: there is no such thing as a
> one-element tuple,
> and Python will automatically convert a one-element tuple to a string...
> hence the
> behavior I observed is explained...
>
>>>> a = ('hello','bonjour')
>>>> b = ('hello')
>>>> b
> 'hello'
>>>> a
> ('hello', 'bonjour')
>>>>
>
>
> Did I get this right this time?
Okay, now you're asking a question in a reasonable way, so we can answer :)
The thing you're confused at is that it's not the parentheses that
create a tuple. Parentheses merely group.
>>> 'hello', 'bonjour'
('hello', 'bonjour')
>>> 'hello',
('hello',)
One-element tuples are perfectly possible, but you MUST have a comma,
so you have one at the end. The trailing comma is perfectly legal (and
ignored) on larger tuples.
>>> 'hello', 'bonjour',
('hello', 'bonjour')
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list