Paul's Python CoursePPC

is and ==

Not met yet

== asks whether two things hold the same values. is asks whether they are the same object. Two lists can be equal without being the same list; a copy is equal to its original but is not it. Use is for None and for hunting down shared objects, and == for comparing values.

Try it

main.py

Output

Press Run and what your program prints shows up here.

Easy to get wrong

  • Thinks two equal lists must be the same list, so is is True whenever == is.
  • Thinks == checks whether two names point at the same object rather than comparing contents.
  • Thinks is compares variable names rather than the objects they refer to.
  • Thinks a copy is the same object as the original because it is equal to it.

Where it comes up