Latest web development tutorials

Python3 strip()方法

Python3 字符串 Python3字符串


描述

Python strip() 方法用於移除字符串頭尾指定的字符(默認為空格)。

語法

strip()方法語法:

str.strip([chars]);

參數

  • chars -- 移除字符串頭尾指定的字符。

返回值

返回移除字符串頭尾指定的字符生成的新字符串。

實例

以下實例展示了strip()函數的使用方法:

#!/usr/bin/python3

str = "*****this is string example....wow!!!*****"
print (str.strip( '*' ))

以上實例輸出結果如下:

this is string example....wow!!!

Python3 字符串 Python3字符串