Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #70069 > unrolled thread

the logical operation confused me

Started bylength power <elearn2014@gmail.com>
First post2014-04-11 07:02 +0800
Last post2014-04-10 23:28 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  the logical operation confused me length power <elearn2014@gmail.com> - 2014-04-11 07:02 +0800
    Re: the logical operation confused me Denis McMahon <denismfmcmahon@gmail.com> - 2014-04-10 23:28 +0000

#70069 — the logical operation confused me

Fromlength power <elearn2014@gmail.com>
Date2014-04-11 07:02 +0800
Subjectthe logical operation confused me
Message-ID<mailman.9153.1397170954.18130.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

>>> "ok" or "not ok"
'ok'
>>> "ok" and "not ok"
'not ok'
>>>

why "ok" or "not ok" output "ok"  , "ok" and "not ok"  output "not ok" ?

[toc] | [next] | [standalone]


#70072

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2014-04-10 23:28 +0000
Message-ID<li79f8$6qp$4@dont-email.me>
In reply to#70069
On Fri, 11 Apr 2014 07:02:33 +0800, length power wrote:

>>>> "ok" or "not ok"
> 'ok'
>>>> "ok" and "not ok"
> 'not ok'
>>>>
>>>>
> why "ok" or "not ok" output "ok"  , "ok" and "not ok"  output "not ok" ?

I believe that:

[ (falsey condition) or ]* (first truthy condition) or (any condition) 
[ or (any condition) ]*

will return (first truthy condition)

whereas:

(truthy condition) and [ (truthy condition) and ]* (last truthy condition)

will return (last truthy condition)

where "[ clause ]*" represents an optional clause that may be repeated 
any number of times, "any condition" may evaluate falsey or truthy, 
"first" and "last" relate to the position of the condition type in a left 
to right evaluation sequence.

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web