String exact match

后端 未结 7 1686
悲哀的现实
悲哀的现实 2020-11-29 08:13

I have a string in which the word \"LOCAL\" occurs many times. I used the find() function to search for this word but it returns another word \"Locally\" as wel

7条回答
  •  孤独总比滥情好
    2020-11-29 09:09

    line1 = "This guy is local"
    line2 = "He lives locally"
    
    if "local" in line1.split():
        print "Local in line1"
    if "local" in line2.split():
        print "Local in line2"
    

    Only line1 will match.

提交回复
热议问题