Remove the last part of string separated with dot in Python

前端 未结 2 1046
既然无缘
既然无缘 2021-01-12 18:07

How is it possible to convert in elegant way strings like:

\'test.test1.test2\'
\'test.test3.test4\'

into strings like these:



        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-12 18:41

    Use rsplit to split from the end, limit to 1 split:

    your_string.rsplit('.', 1)
    

提交回复
热议问题