在Python中检查字符串是否被包含在另一个字符串中
使用in函数(最简单)
in函数(最简单)if "ABCD" in "xxxxABCDyyyy":
# whatever INSTANCETYPE_STRING=self.machine_type
cpu_base_set = {"SMALL": 1, "MEDIUM": 2, "LARGE": 4}
for typeKey in cpu_base_set.keys():
if typeKey in INSTANCETYPE_STRING:
cpu_base = cpu_base_set[typeKey]
type_base = typeKeya = ['a', 'b', 'c']
str = "a123"
if any(x in str for x in a):
print "some of the strings found in str"使用index函数
index函数使用find函数
find函数使用re函数
re函数参考
Last updated