-2

How to excecute mutiple value with if condition like below, i tried it but not working

if 'mydj-lb-foxdc01' or 'tsdj-lb-foxdc02' or 'mydj-lb-noivm01' or 'mydj-lb-noivm02' not in line:

Below is working while tried ..

if 'mydj-lb-foxdc01' not in line:
Vadim Kotov
  • 7,766
  • 8
  • 46
  • 61

2 Answers2

1

You can use any() builtin method:

line = 'mydj-lb-noivm01'

if not any(['mydj-lb-foxdc01' in line, 'tsdj-lb-foxdc02' in line, 'mydj-lb-noivm01' in line, 'mydj-lb-noivm02' in line]):
    print('not in line')
else:
    print('in line')

Output:

in line
Andrej Kesely
  • 118,151
  • 13
  • 38
  • 75
0
line = 'mydj-lb-noivm01'

if not any(['mydj-lb-foxdc01' in line, 'tsdj-lb-foxdc02' in line, 'mydj-lb-noivm01' in line, 'mydj-lb-noivm02' in line]):
    print('not in line')
else:
    print('in line')
Yannis
  • 1,572
  • 7
  • 25
  • 44
  • 1
    Code-only answers are not as helpful; please add some words explaining/describing why your suggested code answers the question. – Yannis Jul 30 '18 at 08:26