python strip()方法 去除字符串头尾指定字符 默认为空格、换行符、制表符、回车符

mac2024-03-23  34

Python strip() 方法用于移除字符串头尾指定的字符(默认为空格)或字符序列。 注意:该方法只能删除开头或是结尾的字符,不能删除中间部分的字符。

def strip(self, chars=None): # real signature unknown; restored from __doc__ """ S.strip([chars]) -> str Return a copy of the string S with leading and trailing whitespace removed. 返回删除前导和尾随空格的字符串S的副本。 If chars is given and not None, remove characters in chars instead. 如果给定chars而不是None,则改为删除chars中的字符。 """ return ""

参考文章:Python3 strip()方法

最新回复(0)