Return a copy of the string with leading and trailing characters removed. If chars is omitted or None, whitespace characters are removed. If given and not None, chars must be a string; the characters in the string will be stripped from the both ends of the string this method is called on.
replace():
string.replace(s, old, new[, maxreplace])
Return a copy of string s with all occurrences of substring old replaced by new. If the optional argument maxreplace is given, the first maxreplace occurrences are replaced.
在这个用例中,您需要
replace()
,而不是strip()
strip()
:replace()
:Strings in Python
.strip
从源字符串的开头和结尾删除目标字符串您需要
.replace
.strip()
在必须从字符串的开头和结尾删除传递的字符串时使用。它在中间不起作用。为此,.replace()
用作word.replace('_ ', '')
。这将输出ale
相关问题 更多 >
编程相关推荐