title: How to replace a string conditionally in Python?
body: <p>I need to look for a substring in a string and if I don't find it, perform an action. So I do this, and it works fine:</p>
  
  <pre><code>if 'AAA' not in myString: 
     print "AAA is not in myString"
  </code></pre>
  
  <p>What I need, however, is to avoid cases where AAA is a part of XAAA. In other words, I don't want my script to notice any presence of "XAAA" when it does  <code>if 'AAA' not in myString</code>. So how can I modify the above if-clause to the following:</p>
  
  <pre><code>if 'AAA' not in myString except for cases where 'AAA' is a part of 'XAAA':
      print "AAA is not in myString"
  </code></pre>