Delete Chars in Python

后端 未结 4 669
清歌不尽
清歌不尽 2021-01-22 02:12

does anybody know how to delete all characters behind a specific character??

like this:

http://google.com/translate_t

into

<         


        
4条回答
  •  长情又很酷
    2021-01-22 02:28

    if you're asking about an abstract string and not url you could go with:

    >>> astring ="http://google.com/translate_t"
    >>> astring.rpartition('/')[0]
    http://google.com
    

提交回复
热议问题