首页 > 编程语言 > 详细

python中字符串的strip(),lstrip(),rstrip()的含义

时间:2020-06-20 09:58:29      阅读:60      评论:0      收藏:0      [点我收藏+]

 

 

string.lstrip(s[, chars])

Return a copy of the string with leading 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 beginning of the string this method is called on.

Changed in version 2.2.3: The chars parameter was added. The chars parameter cannot be passed in earlier 2.2 versions.

string.rstrip(s[, chars])

Return a copy of the string with 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 end of the string this method is called on.

Changed in version 2.2.3: The chars parameter was added. The chars parameter cannot be passed in earlier 2.2 versions.

string.strip(s[, chars])

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, charsmust be a string; the characters in the string will be stripped from the both ends of the string this method is called on.

Changed in version 2.2.3: The chars parameter was added. The chars parameter cannot be passed in earlier 2.2 versions.


 

 

1

2

3

4

demoStr.lstrip() = 去除left左边的白空格  = "hello wold !    "

demoStr.rstrip() = 去除right右边的白空格 = "      hello wold !"

 

demoStr.strip() = demoStr.lstrip().rstrip()=去除left左边和right右边=去除首尾的白空格="hello wold !"


python中字符串的strip(),lstrip(),rstrip()的含义

原文:https://www.cnblogs.com/wkwzn2019/p/13167327.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!