- theString = 'saaaay yes no yaaaass'
- print theString.strip('say')
yes no (注意yes和no的前后分别有空格,所以到那就暂停了)
比较简单吧,lstrip和rstrip原理是一样的。注意:当没有传入参数时,是默认去除首尾空格的。
- theString = 'saaaay yes no yaaaass'
- print theString.strip('say')
- print theString.strip('say ') #say后面有空格
- print theString.lstrip('say')
- print theString.rstrip('say')
yes no
es no
yes no yaaaass
saaaay yes no