fj1*_*23x 15 python string split
我有以下字符串:
"hello.world.foo.bar"
我想拆分(使用"."
as分隔符,只想从头到尾获得两个元素),如下所示:
["hello.world.foo", "bar"]
我怎么能做到这一点?到底存在限制?
fal*_*tru 27
使用str.rsplit
指定maxsplit(第二个参数)为1
:
>>> "hello.world.foo.bar".rsplit('.', 1) # <-- 1: maxsplit
['hello.world.foo', 'bar']
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13761 次 |
最近记录: |