在平時我們可能會經常使用strip()方法, 注意這里沒有傳入任何參數, 該方法會取出字符串兩端的空格. 而實際上strip方法也可以傳入參數來進行對字符串首尾進行過濾操作. 與它一起的還有lstrip和rstrip方法.
theString = 'saaaay yes no yaaaass'
print theString.strip('say')
yes no
這樣theString首尾字符在['s', 'a', 'y']中的字符將會被過濾掉. lstrip和rstrip原理以及用法和strip一樣.
posted on 2009-06-04 20:22
周銳 閱讀(4050)
評論(0) 編輯 收藏 所屬分類:
Python