Python's many ways of string formatting — are the older ones (going to be) deprecated?

前端 未结 5 1865
自闭症患者
自闭症患者 2020-11-22 07:01

Python has at least six ways of formatting a string:

In [1]: world = \"Earth\"

# method 1a
In [2]: \"Hello, %s\" % world
Out[2]: \'Hello, Earth\'

# method          


        
5条回答
  •  灰色年华
    2020-11-22 07:28

    Guido's latest position on this seems to be indicated here:

    What’s New In Python 3.0

    PEP 3101: A New Approach To String Formatting

    A new system for built-in string formatting operations replaces the % string formatting operator. (However, the % operator is still supported; it will be deprecated in Python 3.1 and removed from the language at some later time.) Read PEP 3101 for the full scoop.

    And the PEP3101 itself, which has the last modified dating back to (Fri, 30 Sep 2011), so no progress as of late on that one, I suppose.

提交回复
热议问题