Python- how to verify if a string ends with specific string?

前端 未结 4 1404
失恋的感觉
失恋的感觉 2020-12-07 06:21

I have the following string for example: \' 24499 ? 00:02:05 sys-yg-ys\'

How can I verify if the string ends with a string which I got from a

相关标签:
4条回答
  • 2020-12-07 06:33

    you could use

     string.find("substring")
    

    That should do it

    0 讨论(0)
  • 2020-12-07 06:37
    re.match(r"^.+(sys-yg-ys)$", string)
    
    0 讨论(0)
  • 2020-12-07 06:38

    try this:

    line = '  24499 ?   00:02:05 sys-yg-ys'
    result = False
    print("Before test: " + str(result))
    result = line.endswith('ys')
    print("After test: " + str(result))
    

    output:

    Before test: False
    After test: True
    

    why you want to add 'start' and 'end' parameter?

    0 讨论(0)
  • 2020-12-07 06:40

    The str.endswith() function will do this. For example: yourstring.endswith("sys-yg-ys")

    0 讨论(0)
提交回复
热议问题