New submission from Stéphane Henriot: A few days ago, the following behavior surprised me.
>>> "".replace("", "prefix", 1) '' >>> "".replace("", "prefix") 'prefix' It seems to me this edge case isn't correctly documented/implemented. I tested with python 2.7, 3.4 and 3.5, I guess it applies for other versions as well. Here are a few elements, for reference. « string.replace(s, old, new[, maxreplace]) Return a copy of string s with all occurrences of substring old replaced by new. If the optional argument maxreplace is given, the first maxreplace occurrences are replaced. » >>> "" in "" True >>> "".count("") 1 >>> "".find("") 0 https://hg.python.org/cpython/file/2.7/Objects/stringobject.c#l2750 https://hg.python.org/cpython/file/default/Objects/unicodeobject.c#l10479 Thanks, Stéphane. ---------- messages: 275140 nosy: Stéphane Henriot priority: normal severity: normal status: open title: Replace and empty strings type: behavior _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue28029> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com