On Fri, May 6, 2011 at 1:46 AM, Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> wrote: > On Fri, 06 May 2011 10:00:30 +0200, Web Dreamer wrote: >> Jabba Laci a écrit ce vendredi 6 mai 2011 09:18 dans >> <mailman.1229.1304666321.9059.python-l...@python.org> : >>> Hi, >>> >>> Which is the preferred way of string formatting? >>> >>> (1) "the %s is %s" % ('sky', 'blue') >>> >>> (2) "the {0} is {1}".format('sky', 'blue') >>> >>> (3) "the {} is {}".format('sky', 'blue') >>> >>> As I know (1) is old style. (2) and (3) are new but (3) is only >>> supported from Python 2.7+. >>> >>> Which one should be used? >> >> According to python's documentation, (3) and (2) are preferred and (1) >> is deprecated. > > I think you are wrong, % formatting is not deprecated. Do you have a link > showing otherwise?
I'm not them, but: "Note: The formatting operations described here [involving %] are obsolete and may go away in future versions of Python. Use the new String Formatting [i.e. format()] in new code." http://docs.python.org/dev/library/stdtypes.html#old-string-formatting-operations Technically, not formally deprecated, but such a characterization isn't too far off the mark either. Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list