<div dir="ltr"><span style="font-size:12.8000001907349px">Hi,</span><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px">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.</div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px">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.</div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px">Kind regards</div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-07-10 14:04 GMT+02:00 candide <span dir="ltr"><<a href="mailto:c.candide@laposte.net" target="_blank">c.candide@laposte.net</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">Le vendredi 10 juillet 2015 04:02:56 UTC+2, Chris Angelico a écrit :<br>
<br>
<br>
<br>
> I'm not sure what contradiction you're referring to, here. The<br>
> evaluation that you're pointing out says, as Terry showed via the<br>
> disassembly, that Python's first action is to look up the name 't' and<br>
> grab a reference to whatever object it points to.<br>
<br>
<br>
</span>But in order to perform an operation, the interpreter has to evaluate the operands and "evaluating" is not "grabbing a reference to".<br>
<span class=""><br>
> The execution of<br>
> t.sort() has to happen before the multiplication, because of the<br>
> parentheses.<br>
><br>
<br>
<br>
<br>
</span>Official docs explains what evaluation is :<br>
<br>
When the name is bound to an object, evaluation of the atom yields that object.<br>
<br>
So, since the Python interpreter is performing evaluation from left to right, the first operand of the expression :<br>
<br>
t*(1+int(bool(t.sort())))<br>
<br>
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.<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
<br>
--<br>
<a href="https://mail.python.org/mailman/listinfo/python-list" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-list</a><br>
</font></span></blockquote></div><br></div>