[Tutor] String formatting question.

James Reynolds eire1130 at gmail.com
Tue Mar 29 22:28:21 CEST 2011


On Tue, Mar 29, 2011 at 4:21 PM, Corey Richardson <kb1pkl at aim.com> wrote:

> On 03/29/2011 03:41 PM, Prasad, Ramit wrote:
> > Is there a difference (or preference) between using the following?
> > "%s %d" % (var,num)
> > VERSUS
> > "{0} {1}".format(var,num)
> >
> >
> > Ramit
>
> If you're using Python 3, use the second one. If you're using Python 2,
> you have no option but to use the first, as far as I know. Maybe Python
> 2.7 has that formatting, I'm not sure.
>
> --
> Corey Richardson
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>




you can use string{0}.format(var) in python 2.6. I use it all the time. I
never use the other % method.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110329/928ea91d/attachment.html>


More information about the Tutor mailing list