为什么 python 的 strip 和 lstrip 方法在这种情况下没有按预期运行?

Why aren't python's strip and lstrip methods behaving as expected in this case?

我正在尝试从混乱的 CSV 字符串中删除一些垃圾,但我不明白为什么 strip 和 lstrip 没有按预期运行。

我期待 return "ABC" 但似乎无法删除这些字符。

>>> a = '","ABC"'
>>> a
'","ABC"'
>>> a.strip('",')
'ABC'
>>> a.lstrip('",')
'ABC"'
  • a.lstrip('",') 删除 a 开头的所有 ',''"'。 (条。)
  • a.rstrip('",') 删除 a 末尾的所有 ',''"'。 (条。)
  • a.strip('",') 删除 a 两侧的所有 ',''"'