开发者

python check pattern in string [duplicate]

开发者 https://www.devze.com 2023-03-11 04:44 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Python - Check If Word Is In A String.
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

精彩评论

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