Create a tuple of 1 elements (1,)
To create a 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 = ()
>>> T
()
What about creating a tuple with 1 elements? To try:
>>> t = (1)
>>> T
1
It seems to be wrong! T is not a tuple, but an integer 1. Why is it?
Because () both can represent a tuple, and can be used as parentheses to indicate the priority of the operation, the result (1) is calculated by the Python interpreter result 1, resulting in we get not 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,)
>>> T
(1,)
Python also automatically adds a "," when printing cell tuples, in order to tell you more explicitly that this is a tuple.
The multivariate tuple plus does not add this extra "," effect is the same:
>>> T = (1, 2, 3,)
>>> T
(1, 2, 3)
Python creates special tuple tuple