Re: tuples in conditional assignment (Ben Finney)

2015-11-24 Thread George Trojan
Ben Finney writes: Ben Finney Date: 11/24/2015 04:49 AM To: python-list@python.org George Trojan writes: The following code has bitten me recently: t=(0,1) x,y=t if t else 8, 9 print(x, y) (0, 1) 9 You can simplify this by taking assignment out of the picture:: >>> t = (0, 1)

Re: tuples in conditional assignment

2015-11-24 Thread Steven D'Aprano
On Tue, 24 Nov 2015 02:25 pm, George Trojan wrote: > The following code has bitten me recently: > > >>> t=(0,1) > >>> x,y=t if t else 8, 9 > >>> print(x, y) > (0, 1) 9 > > I was assuming that a comma has the highest order of evaluation, that is > the expression 8, 9 should make a tuple. Why t

Re: tuples in conditional assignment

2015-11-23 Thread Ben Finney
George Trojan writes: > The following code has bitten me recently: > > >>> t=(0,1) > >>> x,y=t if t else 8, 9 > >>> print(x, y) > (0, 1) 9 You can simplify this by taking assignment out of the picture:: >>> t = (0, 1) >>> t if t else 8, 9 ((0, 1), 9) So that's an “expression list”

tuples in conditional assignment

2015-11-23 Thread George Trojan
The following code has bitten me recently: >>> t=(0,1) >>> x,y=t if t else 8, 9 >>> print(x, y) (0, 1) 9 I was assuming that a comma has the highest order of evaluation, that is the expression 8, 9 should make a tuple. Why this is not the case? George -- https://mail.python.org/mailman/list