[Tutor] String formatting question.

Corey Richardson kb1pkl at aim.com
Tue Mar 29 22:21:19 CEST 2011


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


More information about the Tutor mailing list