Python's Create cell element tuple
Tuple and list, can contain 0, one and any number of elements.
A tuple that contains multiple elements, which we have created earlier.
A tuple of 0 elements, which is an empty tuple, is represented directly by ():
>>> t = () >>> print t ()
What about creating a tuple with 1 elements? To try:
>>> t = (1) >>> print T1
It seems to be wrong! T is not a tuple, but an integer 1. Why is it?
Because () both can represent a tupleand can be used as parentheses to indicate the priority of the operation, the result (1) is calculated by the Python interpreter as result 1, which results in not being a tuple, but an integer 1.
It is precisely because the tuple with the () definition of a single element is ambiguous, so Python specifies that the element tuple should have a comma ",", which avoids ambiguity:
>>> T = (1,) >>> print T (1,)
Python also automatically adds a "," when printing cell tuples, in order to tell you more explicitly that this is a tuple.
multi-element tuple plus this extra "," effect is the same :
>>> T = (1, 2, 3,) >>> print T (1, 2, 3)
Python's Create cell element tuple