[Tutor] What are these two string-formatting styles called?

Steven D'Aprano steve at pearwood.info
Sat Jun 15 13:41:14 CEST 2013


On 15/06/13 20:18, Dotan Cohen wrote:
> On Fri, Jun 14, 2013 at 6:46 PM, Steven D'Aprano <steve at pearwood.info> wrote:
>> On 15/06/13 01:23, Dotan Cohen wrote:
>>>
>>> What are these two string-formatting styles called?
>>> '%.3f' % x
>>> '{0:.3f}'.format(x)
>>
>>
>> "String formatting", and "string formatting" *wink*
>>
>> Sometimes the first is called "string interpolation". Sometimes it is called
>> "printf-style formatting", after the C function.
>>
>
> Thank you. If I were to say "I prefer the first type over the second
> type", without having the two types in front of me to demostrate which
> is 'first' and which is 'second', then how might I word that? "I
> prefer printf-style formatting over <?>".

"I prefer % formatting over str.format method."

"I prefer percent-formatting over brace-formatting."

"I prefer C-style string formatting over the newer string format method."


(or vice versa).



-- 
Steven


More information about the Tutor mailing list