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


Groups > comp.lang.python > #6024

Re: and becomes or and or becomes and

References <mailman.1925.1306092188.9059.python-list@python.org> <j24jt6ljbqo1au73alobito5v4284a75lk@4ax.com>
Date 2011-05-23 09:28 +1000
Subject Re: and becomes or and or becomes and
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1941.1306106923.9059.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, May 23, 2011 at 8:39 AM, Tim Roberts <timr@probo.com> wrote:
> That IS funny.  Interesting how a careful choice of arugments will fool us.
> One of my favorite math jokes is like that.  A teacher asked a student to
> reduce the following fraction:
>  16
>  ----
>  64
>
> He says "all I have to do is cancel out the sixes, so the answer is 1/4".

I like. :)

But in the OP, the difference between "and" and "&", or "or" and "|",
is subtle yet absolute. They are completely different operators. The
bitwise operators function like the arithmetic operators - evaluate
both operands, then do something that combines them into one value.
The logical operators, though, are more like the if statement:

q = a and b

is similar to:

if a:
  q = a
else:
  q = b

(Pedants, please note that I said "similar" not "equivalent".) They
happen to do similar things, but they're completely different in
operation. I do like the humour value from the careful selection of
operands though!

Chris Angelico

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

and becomes or and or becomes and Stef Mientki <stef.mientki@gmail.com> - 2011-05-22 21:23 +0200
  Re: and becomes or and or becomes and Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-05-22 23:57 +0200
    Re: and becomes or and or becomes and Terry Reedy <tjreedy@udel.edu> - 2011-05-22 18:14 -0400
  Re: and becomes or and or becomes and Tim Roberts <timr@probo.com> - 2011-05-22 15:39 -0700
    Re: and becomes or and or becomes and Chris Angelico <rosuav@gmail.com> - 2011-05-23 09:28 +1000
    Re: and becomes or and or becomes and Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-23 00:30 +0000
      Re: and becomes or and or becomes and rusi <rustompmody@gmail.com> - 2011-05-23 08:30 -0700
        Re: and becomes or and or becomes and bch <bch.itbgcthate@gmail.com> - 2011-05-28 05:27 -0700
          Re: and becomes or and or becomes and Chris Angelico <rosuav@gmail.com> - 2011-05-28 22:50 +1000
    Re: and becomes or and or becomes and Nobody <nobody@nowhere.com> - 2011-05-28 14:31 +0100
      Re: and becomes or and or becomes and Chris Angelico <rosuav@gmail.com> - 2011-05-29 00:04 +1000

csiph-web