Similar to here: Does Python have a string contains substring method? This question only deals with one substring within a string, I want to test one of several.
Something like:
if 'AA' or 'BB' or 'CC' not in string:
print 'Nope'
However, if my test string is:
string='blahblahAA'
the if still evaluates to True and prints the statement. I'm probably just understanding the syntax incorrectly, any help would be appreciated.
Thanks!
Use any for this:
>>> s = 'blahblahAA'
>>> any(x not in s for x in ('AA', 'BB', 'CC'))
True
Your current code is equivalent to:
if ('AA') or ('BB') or ('CC' not in string)
As 'AA' is True(bool('AA') is True), so this always evaluates to True.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With