[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Python-Dev] Examples for PEP 572

On 04.07.2018 21:18, Steven D'Aprano wrote:
> Read the Appendix to the PEP:
> https://github.com/python/peps/blob/master/pep-0572.rst

Yes, I did after I realized where that example came from. But my point 
was actually to understand the evaluation order because Uncle Timmy 
won't be around to explain when new code appears.

> And no, total is not always not equal to total.

Err, yeah. Double negation rules. ;-)

> I read it as:
>      while total != updated total:
>          do stuff
> and find it easier to follow than having to juggle the extra
> book-keeping "old" variable in the original code.

updated_total rocks. Reminds me of those pattern, we usually use in 
those cases.

What just confused me is the evaluation order. It seems to me that it's 
like left-to-right first and then assignment expression.

Using some math-style-inspired markers (execution-irrelevant) would be cool:

while total != (total' := total + term):
 ??? do stuff

total and total' can be different at the same whereas total is total (at 
least in my mental model).
But it seems I need to adapt here.