I am new to Python. I am writing a string function to check if a certain string contains certain multiple values. Is there a syntax in python to allow me to do something like this:
def strParse(str):
a = 't'
b = 'br'
c = 'ht'
if a in str AND b in str AND c in str:
print('Ok!')
(The part I am unsure about is having multiple if statements on line.) Thanks!
Almost correct, just make the and lower-case:
def strParse(str):
a = 't'
b = 'br'
c = 'ht'
if a in str and b in str and c in str:
print('Ok!')
Doesn't cause problems in this case, but you should avoid using variable-names that are also built-in functions (str is a builtin function/type)
If you have more values, you can do the same thing more tidily like so:
values = ['t', 'br', 'ht']
if all(x in instr for x in values):
print("Ok!")
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