Peter Hansen peter at
Wed Sep 24 00:04:26 CEST 2003

Matthew Wilson wrote:
> What would be the best way to strip off the last "_asdf" from
> "asdf_asdf_asdf"?

s = "asdf_asdf_asdf"
without_last_asdf = s[:-len("_asdf")]

of course, that works only if you know it's there...  if not, 
prepending with a test for s.endswith("_asdf") would do the trick.


More information about the Python-list mailing list