FalseExpert Examples

Boolean literal representing false/0

Boolean internals

Exploring the bool type's implementation details.

python
print(bool.__bases__)
print(bool.__mro__)
print(isinstance(False, int))

# Bool is a singleton
a = bool(0)
b = False
print(a is b)

# Can't subclass bool
try:
    class MyBool(bool):
        pass
    print("Subclassing succeeded")
except TypeError as e:
    print(f"Cannot subclass: {e}")

bool is a final subclass of int. True and False are singletons that cannot be recreated.

Want to try these examples interactively?

Open Expert Playground