Python 多项判断_倒序

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]
'''