one-element tuples [Was: Most probably a stupid question, but I still want to ask]
Fillmore
fillmore_remove at hotmail.com
Sun Apr 10 20:22:15 EDT 2016
On 04/10/2016 08:13 PM, Fillmore 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')
> >>>
Hold on a sec! it turns up that there is such thing as single-element tuples in python:
>>> c = ('hello',)
>>> c
('hello',)
>>> c[0]
'hello'
>>> c[1]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: tuple index out of range
>>>
So, my original question makes sense. Why was a discontinuation point introduced by the language designer?
More information about the Python-list
mailing list