Eval of expr with 'or' and 'and' within

Nick the Gr33k support at superhost.gr
Fri Jun 14 05:50:24 EDT 2013


I started another thread because the last one was !@#$'ed up by 
irrelevant replies and was difficult to jeep track.

 >>> name="abcd"
 >>> month="efgh"
 >>> year="ijkl"

 >>> print(name or month or year)
abcd

Can understand that, it takes the first string out of the 3 strings that 
has a truthy value.

 >>> print("k" in (name and month and year))
True

No clue. since the expression in parenthesis returns 'abcd' how can 'k' 
contained within 'abcd' ?

 >>> print(name and month and year)
ijkl

Seems here is returning the last string out of 3 strings, but have no 
clue why Python doing this.

 >>> print("k" in (name and month and year))
True
 >>>

yes, since expression returns 'ijkl', then the in operator can detect 
the 'k' character within the returned string.

This is all iw ant to know.
-- 
What is now proved was at first only imagined!



More information about the Python-list mailing list