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)
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
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”
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