Steve D'Aprano, you're the "master". What's wrong with this concatenation statement?

Ned Batchelder ned at nedbatchelder.com
Wed May 11 15:39:48 EDT 2016


On Tuesday, May 10, 2016 at 8:16:43 PM UTC-4, Thomas 'PointedEars' Lahn wrote:
> DFS wrote:
> 
> > On 5/8/2016 8:44 PM, Thomas 'PointedEars' Lahn wrote:
> >> With the “%” string operator (deprecated),
> > 
> > according to who?
> 
> TFM.
> 

It's easy to be confused on this point.  Early on in the 3.x planning,
there was talk of deprecating %-formatting.  It didn't happen, though.

The docs have discussed it in a few different ways over the years.

Python 3.0 and 3.1 said:

    https://docs.python.org/3.1/library/stdtypes.html#old-string-formatting-operations

    Note: The formatting operations described here are obsolete and
    may go away in future versions of Python. Use the new String
    Formatting in new code. 

3.2 said:

    https://docs.python.org/3.2/library/stdtypes.html#old-string-formatting-operations

    As the new String Formatting syntax is more flexible and handles
    tuples and dictionaries naturally, it is recommended for new code.
    However, there are no current plans to deprecate printf-style formatting.

3.3 and up say:

    https://docs.python.org/3.3/library/stdtypes.html#printf-style-string-formatting

    Note: The formatting operations described here exhibit a variety of
    quirks that lead to a number of common errors (such as failing to
    display tuples and dictionaries correctly).  Using the newer str.format()
    interface helps avoid these errors, and also provides a generally more
    powerful, flexible and extensible approach to formatting text.

So yes, .format is newer and more powerful, and there are good reasons to
recommend it.  But %-formatting is not deprecated.

--NMB.



More information about the Python-list mailing list