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


Groups > comp.lang.python > #43714

Re: Understanding Boolean Expressions

Newsgroups comp.lang.python
References <c581a0ce-a534-42ed-995e-f0a0f1867df8@googlegroups.com>
Subject Re: Understanding Boolean Expressions
From "Rhodri James" <rhodri@wildebst.demon.co.uk>
Organization The Wildebestiary
Message-ID <op.wvnp6ku3a8ncjz@gnudebeest> (permalink)
Date 2013-04-17 00:28 +0100

Show all headers | View raw


On Tue, 16 Apr 2013 23:19:25 +0100, Bruce McGoveran
<bruce.mcgoveran@gmail.com> wrote:

> Hello.  I am new to this group.  I've done a search for the topic about  
> which I'm posting, and while I have found some threads that are  
> relevant, I haven't found anything exactly on point that I can  
> understand.  So, I'm taking the liberty of asking about something that  
> may be obvious to many readers of this group.
>
> The relevant Python documentation reference is:   
> http://docs.python.org/2/reference/expressions.html#boolean-operations.
>
> I'm trying to make sense of the rules of or_test, and_test, and not_test  
> that appear in this section.  While I understand the substance of the  
> text in this section, it is the grammar definitions themselves that  
> confuse me.  For example, I am not clear how an or_test can be an  
> and_test.  Moreover, if I follow the chain of non-terminal references, I  
> move from or_test, to and_test, to not_test, to comparison.  And when I  
> look at the definition for comparison, I seem to be into bitwise  
> comparisons.  I cannot explain this.
>
> Perhaps an example will help put my confusion into more concrete terms.   
> Suppose I write the expression if x or y in my code.  I presume this is  
> an example of an or_test.  Beyond that, though, I'm not sure whether  
> this maps to an and_test (the first option on the right-hand side of the  
> rule) or to the or_test "or" and_test option (the second on the  
> right-hand side of the rule).
>
> If people can offer some thoughts to put me in the right direction (or  
> out of my misery), I would appreciate it.

What the grammar rules are giving you is operator precedence -- "not" has  
higher precedence than "and", which is higher than "or".  As you follow  
the non-terminals back you go further through precedence chain:  
comparisons, then bitwise operators (*not* bitwise comparisons!), then  
shifts, then arithmetic operators, the unary operators, the power  
operator, and finally primaries.

-- 
Rhodri James *-* Wildebeest Herder to the Masses

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


Thread

Understanding Boolean Expressions Bruce McGoveran <bruce.mcgoveran@gmail.com> - 2013-04-16 15:19 -0700
  Re: Understanding Boolean Expressions Walter Hurry <walterhurry@lavabit.com> - 2013-04-16 22:32 +0000
  Re: Understanding Boolean Expressions Dave Angel <davea@davea.name> - 2013-04-16 18:57 -0400
  Re: Understanding Boolean Expressions "Rhodri James" <rhodri@wildebst.demon.co.uk> - 2013-04-17 00:28 +0100
  Re: Understanding Boolean Expressions Terry Jan Reedy <tjreedy@udel.edu> - 2013-04-16 21:23 -0400
  Re: Understanding Boolean Expressions Bruce McGoveran <bruce.mcgoveran@gmail.com> - 2013-04-16 19:29 -0700
  Re: Understanding Boolean Expressions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-17 08:14 +0000
    Re: Understanding Boolean Expressions Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-04-17 11:47 +0300
      Re: Understanding Boolean Expressions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-17 09:20 +0000
        Re: Understanding Boolean Expressions Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-04-17 12:32 +0300

csiph-web