[Tutor] Another assert() question

Marc Tompkins marc.tompkins at gmail.com
Sun Jul 13 22:19:31 CEST 2008


On Sun, Jul 13, 2008 at 1:06 PM, Dick Moores <rdm at rcblue.com> wrote:

>  In other words, "(3,2)" isn't exactly the same as "True" - but it doesn't
> evaluate to False, either, so it's true.
>
>
> So what does (3,2) evaluate to? Or is that a meaningless question? However
> in the following example, "What does z evaluate to?" seems to have a
> meaning, and the answer is not "True" or "False". z evaluates to 12, right?
> Or is there an ambiguity in "evaluate" in Python that is well-understood and
> doesn't cause a problem?
>
> In [28]: x,y = 3,4
>
> In [29]: z = x*y
>
> In [30]: z
> Out[30]: 12
>
> In [31]: bool(z)
> Out[31]: True
>
> In [32]: z == True
> Out[32]: False
>
> In [33]: z == False
> Out[33]: False
>
> Dick
>

It's a matter of context, and a conflation of the phrase "evaluates to" with
"equals" or "is".

In the context of truth or falsehood, "X evaluates to" is the same as
"bool(X)".
In the context of arithmetic, "X evaluates to..." is the same as "X
equals..."  (Then we can go one step further and decide whether the result
is equal to 0, and if it is, then the expression "evaluates to" False.)
In the context of tuples, I can't even get my head around what "evaluates
to" would mean.  (3,2) evaluates to... well, (3,2).  It is what it is.


-- 
www.fsrtechnologies.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080713/9a409df2/attachment.htm>


More information about the Tutor mailing list