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

Dotan Cohen dotancohen at gmail.com
Sat Jun 15 12:18:09 CEST 2013


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 <?>".

>> Where in the fine manual is their names shown? Thanks!
>
>
> Like most things to do with strings, the place to start is the section on
> strings:
>
> http://docs.python.org/3/library/stdtypes.html#text-sequence-type-str
>
> which leads to:
>
> http://docs.python.org/3/library/stdtypes.html#str.format
>
> and
>
> http://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting
>

Thanks. Actually, I did read that page but the descriptions only
_describe_ the methods, they don't really give names. I suppose that
printf-style really is given a name, but the other one isn't!

--
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com


More information about the Tutor mailing list