Possible Duplicate:
python .rstrip removes one additional character
i have a string vtype defined as
vtype = "vidis.fit"
i want to strip the final dis.fit away, so
vtype.rstrip("dis.fit")
but the end result is v, rather than vi, the one I expected/wanted. I’m a bit confused about this, anyone?
EDIT
Thanks everyone. I guess the reason why it confused me in the first place is that, the naming of lstrip and rstrip seems suggesting some sequence, although it only matters to white spaces.
rstripactually takes a sequence of characters at the end of a string to strip, not a specific string to strip. It’s removing theibecauseiis in the sequence of characters passed in.For example, the order of characters in
rstripdoesn’t matter:Nor does the number of times a character is in it:
As the docs specify:
EDIT: And for fun, if you really want to solve the “how do I remove a string at the end of a string” problem, use
rfindwith slicing: