Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #93620
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: Evaluation order |
| Date | 2015-07-09 21:45 -0400 |
| References | <436cb6ac-59a4-44f1-be60-cdec1e509296@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.378.1436492779.3674.python-list@python.org> (permalink) |
On 7/9/2015 8:10 PM, candide 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?
No, as shown by the disassembled byte code
>>> dis.dis("t*(1+int(bool(t.sort())))")
1 0 LOAD_NAME 0 (t)
3 LOAD_CONST 0 (1)
6 LOAD_NAME 1 (int)
9 LOAD_NAME 2 (bool)
12 LOAD_NAME 0 (t)
15 LOAD_ATTR 3 (sort)
18 CALL_FUNCTION 0 (0 positional, 0 keyword pair)
21 CALL_FUNCTION 1 (1 positional, 0 keyword pair)
24 CALL_FUNCTION 1 (1 positional, 0 keyword pair)
27 BINARY_ADD
28 BINARY_MULTIPLY
29 RETURN_VALUE
t.sort() sorts in place and returns None
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Evaluation order candide <c.candide@laposte.net> - 2015-07-09 17:10 -0700
Re: Evaluation order Terry Reedy <tjreedy@udel.edu> - 2015-07-09 21:45 -0400
Re: Evaluation order Chris Angelico <rosuav@gmail.com> - 2015-07-10 12:02 +1000
Re: Evaluation order candide <c.candide@laposte.net> - 2015-07-10 05:04 -0700
Re: Evaluation order Ned Batchelder <ned@nedbatchelder.com> - 2015-07-10 05:19 -0700
Re: Evaluation order Terry Reedy <tjreedy@udel.edu> - 2015-07-10 08:27 -0400
Re: Evaluation order Chris Angelico <rosuav@gmail.com> - 2015-07-11 00:27 +1000
Re: Evaluation order Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-07-10 15:49 +0100
csiph-web