[Tutor] What are these two string-formatting styles called?
Dotan Cohen
dotancohen at gmail.com
Sat Jun 15 12:23:21 CEST 2013
On Fri, Jun 14, 2013 at 7:01 PM, Jim Mooney <cybervigilante at gmail.com> wrote:
> On 14 June 2013 08:23, Dotan Cohen <dotancohen at gmail.com> wrote:
>>
>> What are these two string-formatting styles called?
>> '%.3f' % x
>> '{0:.3f}'.format(x)
>
>
> The first one is a string Expression, using % as the overloaded operator
> The second one is a string method, with .format() as the method for a string
> object
>
Thank you. So would it be clear if I were to say "I prefer
printf-style formatting over the format method."?
> put python string expression or python string method in that great
> teaching tool, Google.
>
Thank you. I had in fact Googled for "Python string" and "Python
string variable replacement names" but I didn't get much further than
the fine Python manual which doesn't clearly name the second method. I
suppose that knowing what to Google for is 90% of the way to an
answer!
> I know this since I'm reading that part of my python book right now and can
> actually remember it. Although I fell asleep on the third page of
> explanations of the more convoluted ways to use {}, which can get convoluted
> indeed ;')
>
Oh? Which book is that? I've so far been learning by writing small
applications here and there. I have been meaning to go through Learn
Python The Hard Way for the longest time.
--
Dotan Cohen
http://gibberish.co.il
http://what-is-what.com
More information about the Tutor
mailing list