python - ('a' in 'abc' == True) evaluates to False -
this question has answer here:
this got while fiddling python interpreter
[mohamed@localhost ~]$ python python 2.7.5 (default, apr 10 2015, 08:09:14) [gcc 4.8.3 20140911 (red hat 4.8.3-7)] on linux2 type "help", "copyright", "credits" or "license" more information. >>> 'a' in 'abc' true >>> 'a' in 'abc' == true false >>> 'a' in 'abc' == false false >>> ('a' in 'abc') == true true >>> ('a' in 'abc') == false false >>> ('a' in 'abc' == true) or ('a' in 'abc' == false) false >>> (('a' in 'abc') == true) or (('a' in 'abc') == false) true
my question why using parenthesis gives me intended, , more logically sound, output?
because of operator chaining, in
, ==
not behave together.
'a' in 'abc' == true
transforms -
'a' in 'abc' , 'abc' == true
reference documentation -
comparisons can chained arbitrarily, e.g., x < y <= z equivalent x < y , y <= z , except y evaluated once (but in both cases z not evaluated @ when x < y found false).
the similar thing happens in
, ==
.
Comments
Post a Comment