Question about None
gallium.arsenide at gmail.com
Sat Jun 13 13:23:38 EDT 2009
On Jun 13, 2:29 am, Steven D'Aprano
<st... at REMOVETHIS.cybersource.com.au> wrote:
> Paul LaFollette wrote:
> > 3) (this is purely philosophical but I am curious)
> > Would it not be more intuitive if
> > isinstance(None, <anything at all>) returned true?
> Good grief no!!!
> None is an object. It has a type, NoneType. It's *not* a
> string, or a float, or an int, or a list, so why would
> you want isinstance() to *lie* and say that it is?
Because you might want None to behave as though it were nothing at
Paul LaFollette is probably thinking along the lines of formal logic
or set theory. It's a little bit confused because programming isn't
quite the same as math, and so it's a common question when designing
and implementing programming languages how far to take certain
abstractions. In some languages, nil, null, or none will try to
behave as mathematically close to "nothing" (complete absence of
anything) as possible, even though in reality they have to have some
concrete implementation, such as perhaps being a singleton object.
But mathematically speaking, it's intuitive that "nothing" would match
I find that it's somewhat like the confusion that often occurs
regarding the all() function. Some people are surprised that all()
returns True, but it's the same logic behind the truth of the
statement "every element of the empty set is an integer". It's also
true that every element of the empty set is a float. Or an elephant.
More information about the Python-list