Bug or intended behavior?

Peter Pearson pkpearson at nowhere.invalid
Tue Jun 6 12:44:59 EDT 2017


On Tue, 6 Jun 2017 03:10:05 +1000, Chris Angelico wrote:
> On Tue, Jun 6, 2017 at 3:01 AM, Peter Pearson wrote:
[snip]
>> Say
>>     "foo %s" % (1-2)
>> not
>>     ("foo %s" % 1) - 2
>> .
>>
>> Personally I prefer a less compact but more explicit alternative:
>>
>>     "foo {}".format(1-2)
>
> The trouble with the zen of Python is that people now use the word
> "explicit" to mean "code that I like". What is more explicit here? It
> uses a method call instead of an operator, but either way, it's
> completely explicit that you want to populate the placeholders in a
> template string.

I meant simply that when you call "format", you don't have to think
about the precedence of the "%" operator.  Maybe "explicit" isn't
the right word; I just make fewer mistakes when I stick with things
that I use all the time (function calls, in this case).

-- 
To email me, substitute nowhere->runbox, invalid->com.



More information about the Python-list mailing list