4 ms·
The "trailing comma creates a tuple" bug actually comes from a disconnect between what people think defines a tuple (parenthesis) and what really does (comma).
by trulyme 5y ago
The "trailing comma creates a tuple" bug actually comes from a disconnect between what people think defines a tuple (parenthesis) and what really does (comma). I always put parenthesis around a tuple for clarity.
- tayo42 5y agowhats the reason for allowing like foo, to be a tuple? why not make this a syntax error? is there a use for single value tuples?
- trulyme 5y agoYes, single tuple values are useful for example for passing to a function which expects a tuple (because it might expect zero, one or multiple values). The thing is, your example is the way tuple should be defined. The parenthesis are merely allowed (and ignored). Why? I see this as a mistake of language creators. But to be fair, it is difficult to make a perfect language (or anything really), and Python is pretty close imho.