[Tutor] String formatting question.

Modulok modulok at gmail.com
Wed Mar 30 02:09:09 CEST 2011


For simple strings I use the "%s" % foo version, for more complex stuff I use
the .format() method. I find it easier to control spacing and alignments with
the .format() method, but that's just me.

-Modulok-


On 3/29/11, Blockheads Oi Oi <breamoreboy at yahoo.co.uk> wrote:
> On 29/03/2011 20:41, Prasad, Ramit wrote:
>> Is there a difference (or preference) between using the following?
>> "%s %d" % (var,num)
>> VERSUS
>> "{0} {1}".format(var,num)
>>
>>
>> Ramit
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>  From Python 2.7.1 docs at
> http://docs.python.org/tutorial/inputoutput.html "Since str.format() is
> quite new, a lot of Python code still uses the % operator. However,
> because this old style of formatting will eventually be removed from the
> language, str.format() should generally be used.".
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list