syntax difference

Ben Finney ben+python at benfinney.id.au
Sun Jun 17 01:56:23 EDT 2018


Chris Angelico <rosuav at gmail.com> writes:

> On Sun, Jun 17, 2018 at 3:30 PM, Ben Finney <ben+python at benfinney.id.au> wrote:
> > (or, if you want to continue with the older less-flexible style,

(I gave an unhelpful URL for that documentation. Try this instead
<URL:https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting>.)

> For the record, there's nothing at all wrong with printf-style
> formatting; its flexibility and brevity make it extremely useful in
> many situations.

That isn't the impression I get from the above documentation. It starts
with a clearly worded warning:

    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 formatted string
    literals or the str.format() interface helps avoid these errors.
    These alternatives also provide more powerful, flexible and
    extensible approaches to formatting text.

That states a clear opinion that ‘str.format’ is preferred.

-- 
 \         “True greatness is measured by how much freedom you give to |
  `\      others, not by how much you can coerce others to do what you |
_o__)                                               want.” —Larry Wall |
Ben Finney




More information about the Python-list mailing list