[Tutor] Another assert() question

Dick Moores rdm at rcblue.com
Mon Jul 14 02:08:23 CEST 2008

At 03:57 PM 7/13/2008, bob gailer wrote:
>When all else fails RTFM:
>5.10 Boolean operations
>"In the context of Boolean operations, and also when expressions are 
>used by control flow statements, the following values are 
>interpreted as false: |False|, |None|, numeric zero of all types, 
>and empty strings and containers (including strings, tuples, lists, 
>dictionaries, sets and frozensets). All other values are interpreted as true."


Pretty cryptic, to me at least. Take one of those 2-element tuples, 
that started all this, (3,5). So because it's a non-empty container 
it's value is interpreted as true. That implies (to me at least), 
that it has a value, if unknown (or is it simply (3,5)?) ; however, 
regardless of this value, it is interpreted as true.

To repeat Lutz:

In Python, as in most programming languages, an integer 0 represents 
false, and an integer 1 represents true. In addition, though, Python 
recognizes any empty data structure as false, and any nonempty data 
structure as true. More generally, the notions of true and false are 
intrinsic properties of every object in Python -- each object is 
either true or false, as follows:

-- Numbers are true if nonzero.
-- Other objects are true if nonempty.

He follows that with a list of objects and their "truth values", a 
much more suitable term here than "value", IMHO. Take that z of a 
previous post: z's value is 12; z's truth value is True.

I'll presumptuously, brazenly go further: I have 2 quarrels with 5.10:
1. "interpret" is misleading. Revise, substituting "consider".
2. "value" is misleading. Revise, substituting "truth value".


>Bob Gailer
>919-636-4239 Chapel Hill, NC

More information about the Tutor mailing list