[Tutor] The Boolean operator "and"

Lloyd Kvam pythonTutor at venix.com
Fri Aug 6 14:47:31 CEST 2004


x and y can simply be values.  0, 0.0, None, [], '' all evaluate to
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