Evaluation order

Chris Angelico rosuav at gmail.com
Thu Jul 9 22:02:41 EDT 2015


On Fri, Jul 10, 2015 at 10:10 AM, candide <c.candide at laposte.net> wrote:
> The official doc explains that :
>
> Python evaluates expressions from left to right.
>
> cf. https://docs.python.org/3.3/reference/expressions.html#evaluation-order
>
>
> But consider the following snippet :
>
>
>>>> t=[2020, 42, 2015]
>>>> t*(1+int(bool(t.sort())))
> [42, 2015, 2020]
>>>>
>
>
> Is there not some contradiction with left-right evalutation?

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. The execution of
t.sort() has to happen before the multiplication, because of the
parentheses.

ChrisA



More information about the Python-list mailing list