[Python-Dev] Re: PEP 616 -- String methods to remove prefixes and suffixes

2020年3月20日 17:19:08 -0700

On 2020年03月20日 21:49, Dennis Sweeney wrote:
For clarity, I'll change
 If ``s`` does not have ``pre`` as a prefix, an unchanged copy of ``s`` is 
returned.
to
 If ``s`` does not have ``pre`` as a prefix, then ``s.cutprefix(pre)`` 
returns ``s`` or an unchanged copy of ``s``.
For consistency with the Specification section, I'll also change
 s[len(pre):] if s.startswith(pre) else s
to
 s[len(pre):] if s.startswith(pre) else s[:]
and similarly change the ``cutsuffix`` snippet.
If ``s`` is immutable, why return a copy when the original will do?
 s[len(pre) : ] if pre and s.startswith(pre) else s
 s[ : -len(suf)] if suf and s.endswith(suf) else s
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/AP6L5H4H3E3RP6FZD4NS6NTLNV4KCQMM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to