strip() 方法帶返回所有從字串的開頭和結尾(默認空格字元)剝離字元後的字串副本。
語法
下麵是 strip() 方法的語法-
str.strip([chars]);
參數
-
chars -- 從字串開始處或結束要刪除的字元
返回值
此方法返回所有從字串的開始和結尾剝離後的字串副本。
示例
下麵的示例演示 strip() 方法的使用。
#!/usr/bin/python3 str = "*****this is string example....wow!!!*****" print (str.strip( '*' ))
當我們運行上面的程式,會產生以下結果 -
this is string example....wow!!!