python编程 python判断字符串是否包含字串的方法?

python判断字符串是否包含字串的方法?Python的string对象没有contains方法,因此您不需要使用它字符串。包含但是Python有一种更简单的方法来替换contains函数。方法1:使

python判断字符串是否包含字串的方法?

Python的string对象没有contains方法,因此您不需要使用它字符串。包含但是Python有一种更简单的方法来替换contains函数。方法1:使用in方法实现contains的函数:site=“”if”jb51”in site:Print(”site contains jb51”)输出结果:site contains jb51方法2:使用find函数实现contains s=”this be a string”if s.find(”is”)==-1:Print “no”is”here!“else:print”found”在字符串中是“。"