This is Python 3.4.2

The documentation says that

s2 = s1.strip('a')

will strip out all the 'a' in s1.

When I run it, only the leftmost character - and only if it is 'a' - is stripped.

The default s2 = s1.strip() takes out all whitespace.
PS: I understand that the chars in () are a list.
This is from an IDLE shell:

s2 = 'qazxswedc'.rstrip('x')

(Also with .lstrip('x') and .strip('x') )

Have I found the very last bug in Python?

2 Years
Discussion Span
Last Post by vegaseat

Standard builtin functions have been tested gazillion times by programs all around the world. It is almost impossible that you discover an unknown bug in them. strip() removes characters only at both ends of the string. You will have to use replace()

>>> 'qazxswedc'.replace('x', '')

Edited by Gribouillis


From the Python manual that ships with every installation:
Return a copy of the string with the leading and trailing characters removed. The chars argument is a string specifying the set of characters to be removed. If omitted or None, the chars argument defaults to removing whitespace. ...

Python has an easy syntax, the trick is to get to know the many functions/methods that it offers. Good luck with your studies.

Edited by vegaseat


Ooops. I used a few unfortunate test cases. I also thought that strip took out all whitespace.

Now I get the difference between strip() and replace().

Thank you all for your help.


Most of the time strip() is used to remove whitespaces at either end of a string.

rstrip() is handy for removing trailing (to the right) newline characters that might come in on a multiline text string.

The Python Shell makes it very easy to test these things.

Edited by vegaseat

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.