Jul-21-2017, 01:32 PM
if ('Ed' or 'Bob') in s:This code checks always
if 'Ed' in s:
The or operator is a binary operation, which is checking for trueness.
A str object with the length 0 is False. All other str objects are True.
With your code you'll always get 'Ed' after evaluating the expression.
What you want to do:
s = 'BobTom' for name in ('Bob', 'Ed'): if name in s: print('Name {} is in {}'.format(name, s))If you want to check if any of the names is in the string, you can write it more compact:
any(name in s for name in ('Bob', 'Ed'))If you want to check if all the names are in the string, you can use the built-in function all:
all(name in s for name in ('Bob', 'Ed'))
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!