Parens do create a tuple (was: one-element tuples [Was: Most probably a stupid question, but I still want to ask])
Tim Chase
python.list at tim.thechases.com
Sun Apr 10 20:52:03 EDT 2016
On 2016-04-11 10:45, Ben Finney wrote:
> Also, there is another obvious way to create an empty tuple: call
> the ‘tuple’ type directly:
>
> >>> foo = tuple()
> >>> print(type(foo), len(foo))
> <class 'tuple'> 0
But here the parens make the tuple too:
>>> foo = tuple
>>> print(type(foo))
<class 'type'>
>>> len(foo)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: object of type 'type' has no len()
(totally just yanking chains, throwing pebbles in the pond to watch
the ripples, and otherwise sewing confusion ;-)
-tkc
More information about the Python-list
mailing list