rstrip,strip,lstrip
2012-10-23 10:34
381 查看
rstrip,strip,lstrip三个函数主要用于移除字串中的满足条件的字符,传入参数是一个字符数组,它们分别表示匹配并去掉右边、两边、左边的字符。
当没有参数传入时,strip()表示去除首尾空格,其它两个函数同理。
code:
>>> str = '\tgood to say you,you are a good guys!doddoog! \n'
>>> nospace = str.strip()
>>> nospace
'good to say you,you are a good guys!doddoog!'
>>> nospace.strip('go!od')
' to say you,you are a good guys'
>>> nospace.lstrip('go!od')
' to say you,you are a good guys!doddoog!'
>>> nospace.rstrip('go!od')
'good to say you,you are a good guys'
>>>
应用中用得最多的就是str.rstrip('\n\r'),系统间换行符。
当没有参数传入时,strip()表示去除首尾空格,其它两个函数同理。
code:
>>> str = '\tgood to say you,you are a good guys!doddoog! \n'
>>> nospace = str.strip()
>>> nospace
'good to say you,you are a good guys!doddoog!'
>>> nospace.strip('go!od')
' to say you,you are a good guys'
>>> nospace.lstrip('go!od')
' to say you,you are a good guys!doddoog!'
>>> nospace.rstrip('go!od')
'good to say you,you are a good guys'
>>>
应用中用得最多的就是str.rstrip('\n\r'),系统间换行符。
相关文章推荐
- 浅谈python中截取字符函数strip,lstrip,rstrip
- Python中的strip()和lstrip()以及rstrip()方法的使用
- Python strip、lstrip和rstrip的用法
- Python误区之strip,lstrip,rstrip
- Python中的strip(),lstrip(),rstrip()的用法
- strip()、 lstrip()、 rstrip()使用方法
- python——strip,lstrip和rstrip
- Python中strip(),lstrip(), rstrip()使用方法
- Pandas 文本数据方法 strip( ) lstrip( ) rstrip( )
- Pandas 文本数据方法 strip( ) lstrip( ) rstrip( )
- python的strip(),lstrip()和rstrip()
- python:strip()、rstrip()、lstrip()
- Python-strip(),lstrip(),rstrip()
- python strip() lstrip() rstrip() 使用方法
- 【详解】python中字符串的strip(),lstrip(),rstrip()的含义
- Python strip() lstrip() rstrip() 函数 去除空格
- python中strip(),lstrip(),rstrip()函数的讲解
- python中strip,lstrip,rstrip简介
- python字符串处理rstrip()、lstrip()、strip()函数使用
- 浅谈python中截取字符函数strip,lstrip,rstrip