我需要在字符串中查找子字符串,如果找不到,请执行操作.所以我这样做,它工作正常:
if 'AAA' not in myString:
print "AAA is not in myString"
Run Code Online (Sandbox Code Playgroud)
但是,我需要避免AAA是XAAA的一部分.换句话说,我不希望我的脚本注意到任何"XAAA"的存在 if 'AAA' not in myString.那么如何将上面的if子句修改为以下内容:
if 'AAA' not in myString except for cases where 'AAA' is a part of 'XAAA':
print "AAA is not in myString"
Run Code Online (Sandbox Code Playgroud)