[Tutor] The Boolean operator "and"

Lloyd Kvam pythonTutor at venix.com
Fri Aug 6 15:03:06 CEST 2004


I think this is better phrasing below.  Those values are equivalent to
False when used in a context where a boolean would be appropriate.

http://docs.python.org/lib/truth.html#l2h-90
Lists the values that evaluate as False.

On Fri, 2004-08-06 at 08:47, Lloyd Kvam wrote:
> x and y can simply be values.  0, 0.0, None, [], '' all evaluate to
                                                                   ^^as 
> False.
> >>> x = None
> >>> y = 0.0
> >>> result = x and y
> >>> result
> >>> print result
> None
> >>> print x or y
> 0.0
> 
> Note that the values do NOT get changed to booleans.
> 
> 
> On Fri, 2004-08-06 at 05:10, Glen Wheeler wrote:
> (snipped)
> 
> >   Mr Hetland is (of course) correct in his statement you quote above.  The
> > key part is where he states ``if x is false''.  This is not ``x evaluates to
> > False''.
> > 
> >   A quick interpreter session to hopefully clarify what he is trying to say:
> > 
> > >>> x = 3 < 4
> > >>> x
> > True
> > >>> x is True
> > True
> > # Note how x actually *is* True
> > >>> x is False
> > False
> > >>>
> > 
> >   The point is that any logical expression is not stored as a string, but as
> > either True or False.  This is neat, since it implies that the expected
> > value of any logical expression will be True or False.  Thus, we have if
> > statements.
> >   Any logical statement or expression is evaluated before assignment to the
> > variable holding that statement actually occurs.
> > 
> > >>> x = 1 > 0
> > >>> y = 1 < 0
> > >>> x and y
> > False
> > >>> x or y
> > True
> > >>> x is False
> > False
> > >>> x is True
> > True
> > 
> >   I hope this helps clear things up.
> > 
> >   Glen
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
-- 

Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice:	603-653-8139
fax:	801-459-9582



More information about the Tutor mailing list