A small quiz question

Marko Rauhamaa marko at pacujo.net
Wed Aug 16 14:22:51 EDT 2017


Ian Kelly <ian.g.kelly at gmail.com>:
> On Wed, Aug 16, 2017 at 6:51 AM, Dennis Lee Bieber
> <wlfraed at ix.netcom.com> wrote:
>>>def f(i): print(i); return i;
>>>>>>f(4)**f(1)**f(2)
>>>>>>> As a first guess
>>>> 2
>> 1
>> 4
>>>> 4
>>>> since in many languages, exponentiation associates right to left
>> I thought the same thing but figured there was no reason to eval f(2)
> before f(1), so I came up with
>> 1
> 2
> 4
> 4
>> which is also wrong.

 Python evaluates expressions from left to right.
 <URL: https://docs.python.org/3/reference/expressions.html#evaluati
 on-order>
Marko


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /