[Tutor] 2 vs 3

Steven D'Aprano steve at pearwood.info
Mon Sep 7 13:34:52 CEST 2015


On Mon, Sep 07, 2015 at 11:32:32AM +0200, Laura Creighton wrote:
> In a message of Mon, 07 Sep 2015 10:16:16 +0100, Alan Gauld writes:
> 
> >And of course if you are really moving to the v3 way of
> >doing things you should move to using the new string
> >formatting style.
> 
> I don't think there is any great push to prefer the new style over
> the old style 'just because' when you are doing simple things.

If you're referring to "%s" % x versus "{}".format(x), no, there's no 
official push for format. They tried that, but the push-back from people 
who like the %s formatting was too large.

%s formatting is NOT deprecated, and will not be any time in the 
forseeable future;

%s formatting is still necessary for anyone who wants to write code that 
works with version 2.4 on up;

format() is more powerful, but also slower.

Of course individual projects and work-places may include their own 
in-house rules, which may prefer %s or format. But as far as Python the 
language goes, you can use whichever you prefer.


-- 
Steve


More information about the Tutor mailing list