Quantcast
Channel: How to replace a string conditionally in Python? - Stack Overflow
Viewing all articles
Browse latest Browse all 5

How to replace a string conditionally in Python?

$
0
0

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:

if 'AAA' not in myString:    print "AAA is not in myString"

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 if 'AAA' not in myString. So how can I modify the above if-clause to the following:

if 'AAA' not in myString except for cases where 'AAA' is a part of 'XAAA':    print "AAA is not in myString"

Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles





Latest Images