描述
Python strip() 方法用於刪除字符串頭部和尾部指定的字符,默認字符為所有空字符,包括空格、換行(\n)、制表符(\t)等。
語法
strip() 方法語法:
S.strip([chars])
參數
- chars -- 可選參數,要刪除的指定字符,默認字符為所有空字符,包括空格、換行(\n)、制表符(\t)等。
返回值
返回刪除字符串頭部和尾部指定的字符后生成的新的字符串。
實例
以下實例展示了 strip() 方法的使用方法:
#!/usr/bin/python3 S = "*****this is string example....wow!!!*****" print (S.strip( '*' ))
以上實例輸出結果如下:
this is string example....wow!!!