[Python-Dev] PEP 498: Literal String Interpolation is ready for pronouncement (original) (raw)
Guido van Rossum guido at python.org
Sat Sep 5 17:55:42 CEST 2015
- Previous message (by thread): [Python-Dev] PEP 498: Literal String Interpolation is ready for pronouncement
- Next message (by thread): [Python-Dev] PEP 498: Literal String Interpolation is ready for pronouncement
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sat, Sep 5, 2015 at 1:44 AM, haypo s <victor.stinner at gmail.com> wrote:
2015-09-05 5:01 GMT+02:00 Guido van Rossum <guido at python.org>: > And I'm ready to accept it. I'll wait until Tuesday night (Monday's a > holiday in the US) in case anything unforeseen comes up, but this is really > the Last Call for this PEP.
String concatenation is inefficient in Python because strings are immutable. There is a micro-optimization which tried to reduce the bad performances of a+b, but it's better to avoid it. Python replaces >'abc' 'def'< with a single string >'abcdef'<. It's_ _done by the parser, there is no overhead at runtime._ _PEP 498 allows to write >'abc' f'string'< which is replaced with_ _>'abc' 'string'.format()< whereas str+str is a bad practice._ _I would prefer to force users to write an explicit '+' to remind them_ _that there are more efficient ways to concatenate strings like_ _''.join((str1, str2)) or putting the first string in the f-string:_ _>f'abcstring'<. Section in the PEP: https://www.python.org/dev/pepsstring/pep-0498/#concatenating-strings Victor
What does the extra + buy users? It's just more punctuation noise. The implementation is intentionally left unspecified by the PEP; it should be possible to design an implementation that combines all the parts together more efficiently than the use of + (e.g. using a "string builder" object internally).
-- --Guido van Rossum (python.org/~guido) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20150905/ecb16a78/attachment.html>
- Previous message (by thread): [Python-Dev] PEP 498: Literal String Interpolation is ready for pronouncement
- Next message (by thread): [Python-Dev] PEP 498: Literal String Interpolation is ready for pronouncement
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]