在3rd之后删除所有内容。在Python中

run*_*aul -1 python

我的Python程序中有一个字符串。我想在第三次之后剥离所有东西.。我已经尝试过strip()split()但是没有得到预期的输出。这该怎么做?

小智 5

你是这个意思吗?

s = 'aaa.bbb.ccc.xxx.xxx.xxx'
stripped = '.'.join(s.split('.')[:3])
print(stripped)
Run Code Online (Sandbox Code Playgroud)