Repaso
EspaƱol
PythonCorePY-04

What does this print?

a = [1, 2]
b = [1, 2]
print(a == b, a is b)

Options

  1. True True
  2. True False (Correct option)
  3. False False
  4. False True

Answer

True False

Why

== asks: do both objects contain the same value? is asks: are they literally the same object in memory?

a and b are two different lists that happen to contain the same numbers, so == is True and is is False.

Use is only to compare with singletons like None: if x is None:.

Remember

== compares values, is compares identity.

Key terms

Practice this question in Repaso