python - If statement check list contains is returning true when it shouldn't -


i have list contains values:

['1', '3', '4', '4'] 

i have if statement check if values contained within list output statement:

if "1" , "2" , "3" in columns:     print "1, 2 , 3" 

considering list doesn't contain value "2", should not print statement, is:

output:

1, 2 , 3 

can explain why case? way python reads list making occur?

it gets evaluated in order of operator precedence:

if "1" , "2" , ("3" in columns): 

expands into:

if "1" , "2" , true: 

which evaluates ("1" , "2") leaving with:

if "2" , true 

finally:

if true: 

instead can check if set of strings subset of columns:

if {"1", "2", "3"}.issubset(columns):     print "1, 2 , 3" 

Comments

Popular posts from this blog

Upgrade php version of xampp not success -

amazon web services - S3 and apache mod_proxy with basic authentication -

powershell - This solution contains one or more assemblies targeted for the global assembly cache -