def sstrip(a):
b=raw_input("enter the string to be stripped off")
i=a.strip(b)
print i
k=raw_input("enter the string")
sstrip(k)
输出:
enter the string - is it available?
enter the string to be stripped off - is
t available?
在上面的程序中,i是两个字符串的一部分,is和it..“it”是一个mid文字输入我也会脱光衣服。你知道吗
有人能帮我吗
str.strip
按字符分隔(一直删除,直到到达参数中没有的字符为止),问题是您在输入中的is
之前包含了一个空格:如果实际要做的是从较大字符串的开始或结束处对子字符串进行切片,则可以使用以下方法:
从你程序中的提示来看
您希望
strip()
去掉子字符串前缀和后缀。它不会。strip()
删除不需要的字符。你知道吗如果要从字符串
a
中的任何位置删除子字符串b
的一个实例:另一方面,如果您只想删除前缀和后缀,就像
strip()
所做的那样:如果你想删除同一前缀或后缀子串的多个出现,同样像
strip()
,那么用while
代替if
。你知道吗相关问题 更多 >
编程相关推荐