testing一个string的子string?

有没有简单的方法来testing一个Pythonstring“xxxxABCDyyyy”,看看是否包含“ABCD”?

if "ABCD" in "xxxxABCDyyyy": # whatever 

还有其他几种方法,除了使用“in”操作符(最简单)

index()

 >>> try : ... "xxxxABCDyyyy".index("test") ... except ValueError: ... print "not found" ... else: ... print "found" ... not found 

find()

 >>> if "xxxxABCDyyyy".find("ABCD") != -1: ... print "found" ... found 

re

 >>> import re >>> if re.search("ABCD" , "xxxxABCDyyyy"): ... print "found" ... found