[issue28029] Replace and empty strings
STINNER Victor
report at bugs.python.org
Mon Oct 28 11:58:59 EDT 2019
STINNER Victor <vstinner at python.org> added the comment:
The current behavior is really surprising.
>>> "".replace("", "|")
'|'
>>> "".replace("", "|", -1)
'|'
vs
>>> "".replace("", "|", 0)
''
>>> "".replace("", "|", 1)
''
>>> "".replace("", "|", 1000)
''
I always expect "|".
---
This behavior makes sense to me:
>>> "abc".replace("", "|")
'|a|b|c|'
>>> "abc".replace("", "|", -1)
'|a|b|c|'
>>> "abc".replace("", "|", 0)
'abc'
>>> "abc".replace("", "|", 1)
'|abc'
>>> "abc".replace("", "|", 100)
'|a|b|c|'
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue28029>
_______________________________________
More information about the Python-bugs-list
mailing list