How to use text strip() function?

后端 未结 2 489
执念已碎
执念已碎 2021-01-26 03:30

I can strip numerics but not alpha characters:

>>> text
\'132abcd13232111\'

>>> text.strip(\'123\')
\'abcd\'

Why the followi

2条回答
  •  南笙
    南笙 (楼主)
    2021-01-26 04:09

    The reason is simple and stated in the documentation of strip:

    str.strip([chars])
    
    Return a copy of the string with the leading and trailing characters removed. 
    The chars argument is a string specifying the set of characters to be removed.
    

    'abcd' is neither leading nor trailing in the string '132abcd13232111' so it isn't stripped.

提交回复
热议问题