在 Python 中,strip 的用法有以下幾種:
示例:s = " hello world ",s.strip() 結果為 "hello world"
示例:s = ">>>hello world<<<",s.strip("<>") 結果為 "hello world"
示例:s = " hello world",s.lstrip() 結果為 "hello world"
示例:s = ">>>hello world<<<",s.lstrip("<>") 結果為 "hello world<<<"
示例:s = "hello world ",s.rstrip() 結果為 "hello world"
示例:s = ">>>hello world<<<",s.rstrip("<>") 結果為 ">>>hello world"
需要注意的是,strip 只能去除字符串兩端的字符,不會改變字符串內部的字符。