Meaning of None - was PEP 285: Adding a bool type
Bengt Richter
bokr at oz.net
Wed Apr 10 17:51:11 EDT 2002
On Wed, 10 Apr 2002 16:04:45 -0400, "Colin J. Williams" <cjw at sympatico.ca> wrote:
[...html...]
____________________________________________________________________
Steve,
Apologies for the HTML.
Steve Holden wrote:
Sorry abt the format of this posting: OE foundit very difficult to remove
Colin's HTML...
"Colin J. Williams" <cjw at sympatico.ca> wrote in message
news:3CAF6EE6.7564CDF7 at sympatico.ca...
Guido asks seven questions:
[Colin provides seven answers]
> Perhaps we should also be rethinking the meaning of None.
Or the meaning of Life ... :-)
> Maybe it would be better to think of it as a NULL in relational
> algebra.
> Suppose we have a person record (p) with attributes age and sex.
> p.age= 22 and p.sex= F (F asumed to be part of an enumeration)
> then we know something about this person.
> On the other hand, suppose we have p.age= None and p.sex= M
> We know that we have a male of unknown age.
> Suppose now that we ask whether this person's age is greater
> than 25:
> if p.age > 25: ...
> Currently, the response is False, but really we don't know.
> Thus, it might be better to think in terms of a three value
> system False, Unknown, True.
If you really wanted to go this way (and there are worse options), the
"logical" (no pun intended) value to use for Unknow id clearly None itself.
Relational systems mostly seem to return NULL as the result of operations on
NULL, whether they be comparisons or arithmetic operations.
Yes, that would be one approach and is the value used in the examples below. However, None is of NoneType.
Perhaps it would be better to have a value of BoolType.
Note this would introduce three-valued logic into Python, which would be
helluva confusing to beginners, who tend to understand the law of the
excluded middle implicitly.
I wonder about the confusion. It would perhaps add clarity to an aspect of
Python.
Let's look at some examples:
a= -25
b= None
c= +25
d= '0'
print 'Simple comparisons'
print ' a, b, c, d:', `a`, `b`, `c`, `d`
print 'a < b, a < c, a < d:', a < b, a < c, a < d
print 'b < a, b < c, b < d:', b < a, b < c, b < d
print 'c < a, c < b, c < d:', c < a, c < b, c < d
print 'd < a, d < b, d < c:', d < a, d < b, d < c
The result is:
a, b, c, d: -25 None 25 '0'
a < b, a < c, a < d: 0 1 1
b < a, b < c, b < d: 1 1 1
c < a, c < b, c < d: 0 0 1
d < a, d < b, d < c: 0 0 0
If the three value scheme were introduced, the results
would be:
a < b, a < c, a < d: None 1 1
b < a, b < c, b < d: None None None
c < a, c < b, c < d: 0 None 1
d < a, d < b, d < c: 0 None 0
Similarly, for logical operations:
print 'Logical operations'
print '0 or None, 1 or None:', `0 or None`, `1 or None`
print '0 and None, 1 and None:', `0 and None`, `1 and None`
print ' not None:', `not None`
print
The result is:
Logical operations
0 or None, 1 or None: None 1
0 and None, 1 and None: 0 None
not None: 1
With a three value scheme, the results would
be the same for the first two, whereas the
result of `not None` would itself be None.
I would appreciate comments.
Colin W.
______________________________________________________________
HTML on usenet bugs me.
Regards,
Bengt Richter
More information about the Python-list
mailing list