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