Evaluation order

Thierry Chappuis tchappui at gmail.com
Fri Jul 10 08:25:32 EDT 2015


Hi,

No, the value of t is a reference to tje list. So first, (1) the value of
the reference t is recovered, (2) the parenthesis is evaluated, (...) the
whole expression is evaluated.

To evaluate (2), the .sort() call is executed in place with the side effect
of sorting the content of t. t.sort() returns None. When the whole
expression is evaluated, the sorted list will be displayed, as expected.

Kind regards

2015-07-10 14:04 GMT+02:00 candide <c.candide at laposte.net>:

> Le vendredi 10 juillet 2015 04:02:56 UTC+2, Chris Angelico a écrit :
>
>
>
> > I'm not sure what contradiction you're referring to, here. The
> > evaluation that you're pointing out says, as Terry showed via the
> > disassembly, that Python's first action is to look up the name 't' and
> > grab a reference to whatever object it points to.
>
>
> But in order to perform an operation, the interpreter has to evaluate the
> operands and "evaluating" is not "grabbing a reference to".
>
> > The execution of
> > t.sort() has to happen before the multiplication, because of the
> > parentheses.
> >
>
>
>
> Official docs explains what evaluation is :
>
> When the name is bound to an object, evaluation of the atom yields that
> object.
>
> So, since the Python interpreter is performing evaluation from left to
> right, the first operand of the expression :
>
> t*(1+int(bool(t.sort())))
>
> evaluates to [2020, 42, 2015]. Next, the second operatand evaluates to the
> integer 1. So I was expecting the result to be a shallow copy of the first
> list [2020, 42, 2015] (the value of t before side effect produced by the
> sort method). On the contrary, the final result takes into in account the
> side effect and it is as if the first operand has been evaluated twice
> before execution of the multiplication operation.
>
>
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150710/0f16d73b/attachment.html>


More information about the Python-list mailing list