lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Oct 14, 2013 at 3:43 AM, steve donovan
<steve.j.donovan@gmail.com> wrote:
> There's really only two
> cases - it's not like C./Python where you have to consider zero as
> well.  And languages which think that '' is false rightly deserve our
> scorn.


Technically, booleans in Python "are" (for some OO definition of
being) actually ints:

Python 3.3.2 (default, Sep  6 2013, 09:30:10)
[GCC 4.8.1 20130725 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> issubclass(bool, int)
True
>>> isinstance(False, int)
True
>>> bool.__mro__
(<class 'bool'>, <class 'int'>, <class 'object'>)
>>> False + 3
3
>>> True + 3
4


And since you can create types (i.e. classes) that have __nonzero__
(or __bool__ in python3) methods, one has possibly inifinte values to
consider.


But I guess this is somewhat off-topic...

-- 
NI!

() - www.asciiribbon.org
/\ - ascii ribbon campaign against html e-mail and proprietary attachments