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

Chris Angelico rosuav at gmail.com
Thu Mar 29 10:08:42 EDT 2018


On Thu, Mar 29, 2018 at 11:28 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Wed, Mar 28, 2018 at 06:27:19PM +0300, Serhiy Storchaka wrote:
>
>> The optimizer already changes
>> semantic. Non-optimized "if a and True:" would call bool(a) twice, but
>> optimized code calls it only once.
>
> I don't understand this. Why would bool(a) be called twice, and when did
> this change? Surely calling it twice would be a bug.
>
> I just tried the oldest Python 3 I have on this computer, 3.2, and bool
> is only called once.

Technically not bool() itself, but the equivalent. Here's some similar code:


More information about the Python-Dev mailing list

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant