2 ms·
whats 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?
by tayo42 5y ago
whats 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.