Python 中的 strip 3 不是 "working"?

strip in Python 3 is not "working"?

我有以下 string:

s = 'sd sdasd sas sas zxxx df xx de '

当我使用 s.strip('x')我得到以下结果:

'sd sdasd sas sas zxxx df xx de '

为什么 strip() 没有删除所有 'x' 个字符?

来自 Python 3.6 文档:

str.strip([chars]): Return a copy of the string with the leading and trailing characters removed.

这意味着 s.strip('x') 仅从字符串的开头和结尾删除 x(例如 "xxxabcxx".strip('x') == "abc")如果您需要替换字符串中的字符,您可能想要使用str.replace() 方法。