A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2018-March/152497.html below:

[Python-Dev] Subtle difference between f-strings and str.format()

[Python-Dev] Subtle difference between f-strings and str.format() [Python-Dev] Subtle difference between f-strings and str.format()Tim Peters tim.peters at gmail.com
Wed Mar 28 14:26:01 EDT 2018
[Serhiy Storchaka <storchaka at gmail.com>]
> ...
> This is not new. The optimizer already changes semantic.
> Non-optimized "if a and True:" would call bool(a) twice, but optimized code
> calls it only once.

I have a hard time imaging how that could have come to be, but if it's
true I'd say the unoptimized code was plain wrong.  The dumbest
possible way to implement `f() and g()` is also the correct ;-) way:

result = f()
if not bool(result):
    result = g()

For the thing you really care about here, the language guarantees `a`
will be evaluated before `b` in:

    '{}{}'.format(a, b)

but I'm not sure it says anything about how the format operations are
interleaved.  So your proposed transformation is fine by me (your #3:
still evaluate `a` before `b` but ignore that the format operations
may occur in a different order with respect to those).
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4