参数:
chars – 移除字符串头尾指定的字符序列。
返回值:
返回移除字符串头尾指定的字符生成的新字符串。
strip()函数的使用方法:
str = "00000003210ysq01230000000";
print str.strip( '0' ); # 去除首尾字符
str2 = " ysq "; # 去除首尾空格
print str2.strip();
运行结果:
3210ysq0123
ysq
下例演示了只要头尾包含有指定字符序列中的字符就删除:
str = "123ysq321"
print (str.strip( '12' )) # 字符序列为 12
运行结果:
3ysq3