NoneExpert Examples

Represents the absence of a value; Python's null equivalent

None internals

How None works at the CPython level.

python
import dis

# How 'is None' compiles vs '== None'
def check_is(x):
    return x is None

def check_eq(x):
    return x == None

print("x is None bytecode:")
dis.dis(check_is)
print("\nx == None bytecode:")
dis.dis(check_eq)

# 'is None' uses IS_OP (identity check) — O(1)
# '== None' uses COMPARE_OP (calls __eq__) — may be overridden

# Custom class can make == None return True
class Weird:
    def __eq__(self, other):
        return True

w = Weird()
print(f"\nw == None: {w == None}")
print(f"w is None: {w is None}")

'is None' compiles to a fast pointer comparison. '== None' calls __eq__ which can be overridden, making it both slower and potentially incorrect.

Want to try these examples interactively?

Open Expert Playground