is Compares Identity, == Compares Values

is compares object identity while == compares contents; aliasing one list shows mutations propagating, and is None is the idiomatic test.

PythonData Integrity

Code

pythonsnippet
17 lines
a = [1, 2, 3]
b = [1, 2, 3]

# == asks "same contents?", is asks "same object?"
print("values equal:", a == b)
print("same object:", a is b)

# Binding an existing list shares its identity
alias = a
print("alias is a:", alias is a)

# Mutation through the alias shows up in a; b stays independent
alias.append(4)
print("a:", a, "b:", b)

# None is a singleton: is None is the idiomatic emptiness test
print("none check:", b is None, b == None)

Output

Captured from a sandboxed run of this snippet in the build pipeline.

values equal: True
same object: False
alias is a: True
a: [1, 2, 3, 4] b: [1, 2, 3]
none check: False False

What the code does

All the work happens on the top-level bindings: alias.

What to watch for

  • All of it is standard-library — paste it in and it runs.

Taking the usage further

The demo output is labeled (values equal:, same object:, alias is a:), so each line traces straight back to the statement that printed it.

Interactive Tools for This Topic

FAQ

Is the dependency story complicated?
Not at all: zero dependencies, so there is nothing to version or audit. Its state lives in module-level bindings: `alias`.