- 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