It's a syntax thing. What defines the tuple is not the parenthesis, but the presence of the comma:
- Parenthesis around a single scalar expression are used to define order of evaluation:
(1 + 2) * 3
- A sequence of expressions separated by commas defines a tuple:
1, 2, 3
.
- This sequence can then be parenthesized if it needs to be embedded in some other expression:
(1, 2, 3) * 5
is "the tuple (1,2,3) repeated five times".
- Specifically for a single-item tuple, the syntax requires a trailing comma to differentiate it from a parenthesized expression:
0,
is a tuple containing only the element 0; Usually you'd immediately want to parenthesize this expression if you wanted to embed it in a larger expression, e.g. (0,) * 5
("the tuple consisting of zero, multiplied five times"). Whereas 0
and (0)
both mean "the integer zero" (parenthesized in the latter form).
>>> type( (0, ) )
tuple
>>> type ( (0) )
int
So (0) * 5
is "the integer 0 multiplied by 5", giving you 0. There's no tuple involved at any point because the syntax you used does not define a tuple.