我有以下代码:
url = 'abcdc.com'
print(url.strip('.com'))
Run Code Online (Sandbox Code Playgroud)
我期望: abcdc
我有: abcd
现在我做
url.rsplit('.com', 1)
Run Code Online (Sandbox Code Playgroud)
有没有更好的办法?
Python 2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04)
[GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> path = "/Volumes/Users"
>>> path.lstrip('/Volume')
's/Users'
>>> path.lstrip('/Volumes')
'Users'
>>>
Run Code Online (Sandbox Code Playgroud)
我期待输出path.lstrip('/Volumes')应该是/Users