>>> x = ()
>>> type(x)
tuple
I've always thought of ,
as the tuple literal 'constructor,' because, in every other situation, creating a tuple literal requires a comma, (and parentheses seem to be almost superfluous, except perhaps for readability):
>>> y = (1)
>>> type(y)
int
>>> z = (1,)
>>> type(z)
tuple
>>> a = 1,
>>> type(a)
tuple
Why is ()
the exception? Based on the above, it seems to make more sense for it to return None
. In fact:
>>> b = (None)
>>> type(b)
NoneType
("x",)
to be the only special one. It is of course necessary to differentiate between a tuple declaration and an expression wrapped in parentheses. Other than the 1 element case, tuples are created by separating their elements with commas. Since for the zero element case, there are no elements, there's nothing to separate. I've always considered the parentheses to be the key part of the construction. – Lazy