5 ms·
I have never wanted to declare a tuple without surrounding it with (). No? I do that occasionally, e.g.: x, y = 5, 6
by icebraining 13y ago
I have never wanted to declare a tuple without surrounding it with ().
No? I do that occasionally, e.g.:
x, y = 5, 6
- akx 13y agoDoing (x, y) = (5, 6) makes it clearer to "visually grep" that it's not a normal assignment though.
- icebraining 13y agoFair enough, that would be fine by me.
- rnnr 13y agoIt's the comma that determines an expression as a tuple, not the parentheseis.
- lucian1900 13y agoWhich is the source of the original problem, which I've also encountered myself.
- yeukhon 13y agoThat syntax reminds me of trying to do the following print x, print y But I generall find myself doing the , in the situation like (element1,) to create a new tuple.
- herge 13y agoNot all the time. x = , causes a syntax error, while x = (,) creates an empty tuple.
- dalke 13y agoUnder both Python 2.7 and Python 3.3 I get: >>> x=(,) File "<stdin>", line 1 x=(,) ^ SyntaxError: invalid syntax
- Spittie 13y agoFrom the Python docs (https://docs.python.org/3/tutorial/datastructures.html#tuples-and-sequences https://docs.python.org/3/tutorial/datastructures.html#tuple...) > Empty tuples are constructed by an empty pair of parentheses; And it works fine >>> x = () >>> x () I guess Herge mean that? After all, his argument was that a tuple is not always defined by the comma.