开发者

python check pattern in string [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Python - Check If Word Is In A String.

i have a string 开发者_如何学Pythonwhich is a url e.g.

my_url = "http://mysite.com/somefolder/somefile"

I want check if "somefolder" is in the my_url file

how do I do that?


Are you looking for this?

if "/somefolder/" in my_url:
    #whatever


Use:

print 'somefolder' in my_url

OR

print my_url.index('somefolder')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜