Eval of expr with 'or' and 'and' within
Grant Edwards
invalid at invalid.invalid
Fri Jun 14 10:49:41 EDT 2013
On 2013-06-14, Nick the Gr33k <support at superhost.gr> wrote:
> I started another thread
no kidding.
> 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.
Yes, it does. That's the way the language is defined to work. If you
don't like it, pick a different language.
> >>> print("k" in (name and month and year))
> True
>
> No clue. since the expression in parenthesis returns 'abcd'
No it doesn't. Try it:
Python 2.7.3 (default, Mar 20 2013, 14:16:24)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> name="abcd"
>>> month="efgh"
>>> year="ijkl"
>>>
>>> "k" in (name and month and year)
True
>>> (name and month and year)
'ijkl'
>>>
> how can 'k' contained within 'abcd' ?
It doesn't
--
Grant Edwards grant.b.edwards Yow! Am I having fun yet?
at
gmail.com
More information about the Python-list
mailing list