如何在如下所示的if
条件下执行多值运算,我尝试了但没有用
if 'mydj-lb-foxdc01' or 'tsdj-lb-foxdc02' or 'mydj-lb-noivm01' or 'mydj-lb-noivm02' not in line:
下面正在尝试时工作。.
if 'mydj-lb-foxdc01' not in line:
答案 0 :(得分:0)
您可以使用any()
内置方法:
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')
输出:
in line
答案 1 :(得分: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')
答案 2 :(得分:-1)
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')