This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: str.strip() and " behaviour expected?
Type: Stage:
Components: Library (Lib), macOS Versions: Python 3.0
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti, sholvar
Priority: normal Keywords:

Created on 2009-05-17 18:48 by sholvar, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg87999 - (view) Author: Erik Bernoth (sholvar) Date: 2009-05-17 18:48
Hey guys,

is the following behaviour expected? I don't really think so...

$ python
Python 3.0.1 (r301:69597, Feb 14 2009, 19:03:52) 
[GCC 4.0.1 (Apple Inc. build 5490)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> 
>>> 
>>> 
>>> s = ' "Peter"'
>>> s
' "Peter"'
>>> s.strip()
'"Peter"'
>>> s.strip('"')
' "Peter'
>>> s.strip('\"')
' "Peter'
>>> s.strip('\"\"')
' "Peter'
>>> 
>>> 
>>> 
>>> s.strip()
'"Peter"'
>>> s.strip().strip('"')
'Peter'
>>> s.strip('"').strip()
'"Peter'
msg88000 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-05-17 19:12
Yes, it is expected.
When you call .strip() without args it strips the whitespaces, when you
call with an arg it strips only what you specified.
In this example:
>>> s.strip('"')
' "Peter'
the left " is not removed because there's a space in between, in this
example:
>>> s.strip().strip('"')
'Peter'
you first remove the space and then the two ".
History
Date User Action Args
2022-04-11 14:56:49adminsetgithub: 50299
2009-05-17 19:15:46loewissetstatus: open -> closed
resolution: not a bug
2009-05-17 19:12:50ezio.melottisetnosy: + ezio.melotti
messages: + msg88000
2009-05-17 18:48:54sholvarcreate