Here is what you can find in the str.strip
documentation:
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.
Now my question is: which specific characters are considered whitespace?
These function calls share the same result:
>>> ' '.strip()
''
>>> '\n'.strip()
''
>>> '\r'.strip()
''
>>> '\v'.strip()
''
>>> '\x1e'.strip()
''
In this related question, a user mentioned that the str.strip
function works with a superset of ASCII whitespace characters (in other words, a superset of string.whitespace
). More specifically, it works with all unicode whitespace characters.
Moreover, I believe (but I'm just guessing, I have no proofs) that c.isspace()
returns True
for each character c that would also be removed by str.strip
. Is that correct? If so, I guess one could just run c.isspace()
for each unicode character c, and come up with a list of whitespace characters that are removed by default by str.strip
.
>>> ' '.isspace()
True
>>> '\n'.isspace()
True
>>> '\r'.isspace()
True
>>> '\v'.isspace()
True
>>> '\x1e'.isspace()
True
Is my assumption correct? And if so, how can I find some proofs? Is there an easier way to know which specific characters are automatically removed by str.strip
?