-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
  • 8,084
  • 8
  • 48
  • 62

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
  • 168,389
  • 15
  • 48
  • 91
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,682
  • 7
  • 27
  • 45
  • 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