如果字符串不包含指定的子字符串,则包含方法返回False。在这种情况下,我们可以使用split方法将字符串拆分为列表,并使用if语句检查子字符串是否在列表中出现。
示例代码:
s = "hello world"
if "there" in s:
print("Found")
else:
words = s.split()
if "there" in words:
print("Found")
else:
print("Not found")