bool and int

rbowman bowman at montana.com
Tue Jan 24 00:17:50 EST 2023


On Mon, 23 Jan 2023 23:22:00 -0500, Dino wrote:

> $ python Python 3.8.10 (default, Mar 15 2022, 12:22:08)
> [GCC 9.4.0] on linux Type "help", "copyright", "credits" or "license"
> for more information.
>  >>> b = True isinstance(b,bool)
> True
>  >>> isinstance(b,int)
> True
>  >>>
>  >>>
> WTF!


>>> b = True
>>> isinstance(b, bool)
True
>>> isinstance(b, int)
True
>>> c = b + 10
>>> print(c)
11
>>> b = False
>>> c = b + 10
>>> print(c)
10


bool is a subtype of integer. I never dug that deep into Python's guts but 
I assume it goes back to boolean being an afterthought in C. Some people 
fancy it up with #defines but I always use int.  0 is false, anything else 
is true.

C# is pickier, which I guess is a good thing. 


More information about the Python-list mailing list