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 <breamore...@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@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@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor