strip,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'),系统间换行符。