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

Fábio Santos fabiosantosart at gmail.com
Fri Jun 14 06:03:59 EDT 2013


On 14 Jun 2013 10:59, "Nick the Gr33k" <support at superhost.gr> wrote:
>
> 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.

You have been explained with both words, links and examples and now you
dismiss the previous post because it was "difficult to jeep track"?

Anyway. Search for "short circuit logic". Short circuit logic is why python
does it that way.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130614/30bf786d/attachment.html>


More information about the Python-list mailing list