2 ms·
Thanks for reminding me tuples can be instantiated without the use of parenthesis, that's something I usually forget about. I'm much more used to only using co
by joaofcosta 7y ago
Thanks for reminding me tuples can be instantiated without the use of parenthesis, that's something I usually forget about.
I'm much more used to only using commas when extracting values from a tuple, for example:
a, b, c = (1, 2, 3)
I think maybe the only "issue" with the syntax where no parenthesis is used is that, as obvious as it may seem, you can't use it when passing parameters to function. For example:
# Will work
function(parameter, (1,2,3))
# Won't work
function(parameter, 1, 2, 3)
Not really an issue but just nice to know that it doesn't work on every scenario.
Anyway, nice to be reminded of other options :)
- eesmith 7y agoTuples and generator comprehensions also don't mix well: >>> (x, x*2 for x in "qwe") File "<stdin>", line 1 (x, x*2 for x in "qwe") ^ SyntaxError: invalid syntax >>> ((x, x*2) for x in "qwe") <generator object <genexpr> at 0x107821350>