Message275140
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. |
|
Date |
User |
Action |
Args |
2016-09-08 20:30:41 | Stéphane Henriot | set | recipients:
+ Stéphane Henriot |
2016-09-08 20:30:41 | Stéphane Henriot | set | messageid: <1473366641.62.0.989746465638.issue28029@psf.upfronthosting.co.za> |
2016-09-08 20:30:41 | Stéphane Henriot | link | issue28029 messages |
2016-09-08 20:30:41 | Stéphane Henriot | create | |
|