python編程 python判斷字符串是否包含字串的方法?
python判斷字符串是否包含字串的方法?Python的string對象沒有contains方法,因此您不需要使用它字符串。包含但是Python有一種更簡單的方法來替換contains函數(shù)。方法1:使
python判斷字符串是否包含字串的方法?
Python的string對象沒有contains方法,因此您不需要使用它字符串。包含但是Python有一種更簡單的方法來替換contains函數(shù)。方法1:使用in方法實(shí)現(xiàn)contains的函數(shù):site=“”if”jb51”in site:Print(”site contains jb51”)輸出結(jié)果:site contains jb51方法2:使用find函數(shù)實(shí)現(xiàn)contains s=”this be a string”if s.find(”is”)==-1:Print “no”is”here!“else:print”found”在字符串中是“。"