Python 多项判断
原创
©著作权归作者所有:来自51CTO博客作者基督徒Isaac的原创作品,请联系作者获取转载授权,否则将追究法律责任

list_1 = [1,2,3]
list_2 = list_1[::-1] # 倒序
'''判断条件 加括号'''
list_index = []
for index in range(3):
if ( list_1[index]>1 ) & ( list_2[index]<2 ):
list_index.append( index )
print( list_index )
list_index = []
for index in range(3):
if ( list_1[index]>1 ) | ( list_2[index]<2 ):
list_index.append( index )
print( list_index )
'''不加括号 错误'''
list_index = []
for index in range(3):
if list_1[index]>1 & list_2[index]<2:
list_index.append( index )
print( list_index )
list_index = []
for index in range(3):
if list_1[index]>1 | list_2[index]<2:
list_index.append( index )
print( list_index )
'''
[2]
[1, 2]
[1, 2]
[2]
'''