Python Python Collections (2016, retired 2019) Lists Removing items from a list

Lihua Yao
Lihua Yao
4,217 Points

Why the data type of Boolean is int?


list = ["a", 1, 2, 3, False, [1, 2, 3]]
list[4]
False
isinstance(list[4], int)
True


type(False)
<class 'bool'>


isinstance(False, int)
True
isinstance(True, int)
True

1 Answer

Steven Parker
Steven Parker
170,273 Points

This is merely a historical artifact of the linguistic evolution. It prevents code written from before the bool type was added from breaking.

If bool is a possibility, just test for it first:

isinstance(False, bool)
True