Roi*_*ton 15 python python-3.x
我有一个包含路径的字符串
str = "/example/path/with/different/trailing/delimiter\"
Run Code Online (Sandbox Code Playgroud)
我要修剪开头和结尾/和\。Python 3的最佳做法是什么?
目前我正在使用
trimmedPath = str.strip("/\\")
# trimmedPath is "example/path/with/different/trailing/delimiter" as desired
Run Code Online (Sandbox Code Playgroud)
两个问题:
mag*_*ger 12
strip()行动的例子;在这种情况下,请删除前导加号:
In [1]: phone_number = "+14158889999"
In [2]: phone_number.strip('+')
Out[2]: '14158889999'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
33792 次 |
| 最近记录: |