1. 程式人生 > >python判斷字串(string)是否包含(contains)子字串的方法

python判斷字串(string)是否包含(contains)子字串的方法

方法1:使用 in 方法實現contains的功能:

site ='http://www.outofmemory.cn/'if"sharejs"in site:print('site contains sharejs')
                                輸出結果:site contains sharejs

                                方法2:使用find函式實現contains的功能
s ="This be a string"if s.find("is")==-1:print"No 'is' here!"else:print"Found 'is' in the string."