Python - How to cut a string in Python?

前端 未结 6 1504
失恋的感觉
失恋的感觉 2021-02-05 04:09

Suppose that I have the following string:

http://www.domain.com/?s=some&two=20

How can I take off what is after & includin

6条回答
  •  执笔经年
    2021-02-05 04:52

    s[0:"s".index("&")]
    

    what does this do:

    • take a slice from the string starting at index 0, up to, but not including the index of &in the string.

提交回复
热议问题