Python strip()函数中是否有任何错误?

Rak*_*kmo -1 python

创建两个字符串:

s1 = "sha1:abcd"
s2 = "sha1:wxyz"
Run Code Online (Sandbox Code Playgroud)

.strip()在两个字符串上应用函数:

s1.strip("sha1:")
>>> 'bcd'

s2.strip("sha1:")
>>> 'wxyz'
Run Code Online (Sandbox Code Playgroud)

我期待以下输出:

s1.strip("sha1:")
>>> 'abcd'

s2.strip("sha1:")
>>> 'wxyz'
Run Code Online (Sandbox Code Playgroud)

我知道该strip()函数已被弃用.我很想知道这个问题.我浏览了官方文档,但未发现有关":a"或类似内容的特别提及.

而且我也知道其他替代方案,我们可以使用split("sha1:")strip("sha1")跟随strip(":"),给出所需的输出.

大宝剑*_*大宝剑 10

那里

strip(...)
    S.strip([chars]) -> str

    Return a copy of the string S with leading and trailing
    whitespace removed.
    If chars is given and not None, remove characters in chars instead.
Run Code Online (Sandbox Code Playgroud)

注意字符中的字符

文档中详细解释.

  • 为了澄清,它正在从'字符'中删除*任何*字符,意思是任何s,h,a等. (3认同)