is versus ==

is asks whether two names are the same object. == asks whether their values match. Use is None for a missing value.

Syntax

a is b
a == b
value is None
  • Two lists with the same items are equal, but they are not the same object.

Example

a = []
b = a
c = []
print(a is b)
print(a is c)
print(a == c)

Output:

True
False
True

Common mistakes

  • Use == for numbers and text. is with a literal can look like it works and then fail.

Practise it