True — Expert Examples
Boolean literal representing true/1
Boolean singleton internals
Exploring how True works at the CPython level.
python
# True is a singleton a = bool(1) b = True c = bool("yes") print(f"a is b: {a is b}") print(f"a is c: {a is c}") # Memory address is always the same print(f"id(True): {id(True)}") print(f"id(bool(1)): {id(bool(1))}") # Bytecode for boolean operations import dis def check(x): if x: return True return False dis.dis(check)
True and False are singletons — every True in your program is the exact same object. CPython interns them like small integers.
Want to try these examples interactively?
Open Expert Playground