首页 > 其他分享 >strip的功能

strip的功能

时间:2022-12-10 21:55:40浏览次数:37  
标签:功能 元素 空格 xiaomu strip 去掉 hello

strip将去掉字符串左右两边的指定元素,默认是去掉空格

newstr = string.strip(item)

参数:括弧里需要传一个你想去掉的元素,可不填写

' hello xiaomu '.strip()  //hello xiaomu

'hello xiaomu'.strip('h')  //ello xiaomu

strip扩展

1.传入的元素如果不在开头或结尾则无效

2.lstrip仅去掉字符串开头的指定元素或空格

3.rstrip仅去掉字符串结尾的指定元素或空格

str = '   hello   '

str.strip()  //hello   会把hello前后所有的空格都去掉

 

标签:功能,元素,空格,xiaomu,strip,去掉,hello
From: https://www.cnblogs.com/qjb2404/p/16972423.html

相关文章