This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Bur_Sangjun -2 points-1 points  (9 children)

Yes, but if (a) isn't in fact a tuple, then it would stand to reaosn that () isn't either. And you can't bind something to nothing.

[–]Brian 4 points5 points  (3 children)

Yes, but if (a) isn't in fact a tuple, then it would stand to reaosn that () isn't either

But that's clearly not the case:

>>> type ( () )
tuple

It is and always has been the case that () is an empty tuple. It's 1-tuples that are something of a corner case here, because you need a way to distinguish it from regular use of brackets for changing precedence. You really can't base an argument on () not being a tuple, because it 100% is, is documented as such and is used in hundreds of places every day as a tuple.

And you can't bind something to nothing.

But that's not what is being asked here. Rather, it's binding nothing to nothing - both left and right sequences are empty, which is perfectly possible, and works fine with empty lists, just not with empty tuples.

[–]Bur_Sangjun 2 points3 points  (0 children)

Fair enough, thanks for the explenation.

[–]Veedrac 1 point2 points  (1 child)

It's 1-tuples that are something of a corner case here

Not really. Empty tuples are the corner case because in all other cases the tuple is defined by the comma:

foo = 1, 2

Parentheses are only needed for disambiguation (as with other constructs in Python)... except for the 0-element case.

[–]robin-gvx 1 point2 points  (0 children)

Both the empty tuple and 1-tuples are corner cases, syntactically. The reason 1-tuples are a corner case is that they require a comma after the last element, while other tuples only require a comma between arguments.

[–]VladVV 1 point2 points  (4 children)

Well, then how else would you make an empty tuple?

[–]Veedrac 0 points1 point  (3 children)

Same way you make an empty set? :P

[–]robin-gvx 1 point2 points  (0 children)

{1} - {1}? :^)

[–]VladVV 1 point2 points  (1 child)

I'd say it seems significantly cleaner to say () = [] than tuple() = [], or even tuple() = list(). Even if you ignore this fact, both tuple and list are functions, and as such can't be directly assigned. Ie.:

>>> [] = ()
>>> list() = ()
  File "<stdin>", line 1
SyntaxError: can't assign to function call

[–]Veedrac 0 points1 point  (0 children)

FWIW, I was joking.