A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2001-April/014384.html below:

[Python-Dev] string slicing and method consistency

[Python-Dev] string slicing and method consistencyGreg Wilson Greg.Wilson@baltimore.com
Fri, 20 Apr 2001 15:20:53 -0400
One of the students in my class at the Space Telescope
Science Institute ("Hubble R Us") last week brought up
an interesting point: if "abbc"[-1] is "c", and if
"abbc".replace("b", "x", 1) is "axbc", then shouldn't
"abbc".replace("b", "x", -1) be "abxc" (i.e. negative
numbers replace the *last* occurrences of the value)?
Same argument for "split", etc.

Turns out that "abbc".replace("b", "x", -1) is "axxc"
(i.e. negative arguments are ignored).  I would have
expected this to raise a ValueError, if anything.  Is
there a reason for this behavior?  Is it worth making
replace, split, etc. interpret negative indices in the
same way as indexing does?

Thanks,
Greg




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4