Content · Programming · Python

Python Identity Operators: is vs ==

== asks whether two objects compare equal in value; is asks whether they are the exact same object. Use is None to test for the singleton None, not is to compare ordinary numbers or strings. Learn with a clear example.

2 views Published Oct 17, 2026 Updated Oct 18, 2026 Admin

This guide explains Identity Operators: is vs == through a focused example and practical reasoning. No prior knowledge of this specific operation is required.

Understanding the Concept


== asks whether two objects compare equal in value; is asks whether they are the exact same object. Use is None to test for the singleton None, not is to compare ordinary numbers or strings.

When You Would Use This


A shared list and an independent list can contain the same items without sharing identity.

Step-by-Step Example


original_values = [10, 20]
shared_values = original_values
copied_values = [10, 20]
print(original_values == copied_values)
print(original_values is copied_values)
print(original_values is shared_values)
print(None is None)

How the Example Works


Equal contents make the first comparison true. The independently created list is not the same object. The alias references the original object, so its identity check is true.

Example Output


True
False
True
True

Try It Yourself


Make a list alias and explain what happens when you append through the alias.

Common Beginner Mistakes


  • Using is instead of == to compare strings or numbers.
  • Assuming two independent equal lists share one identity.
  • Testing value == None where value is None is more direct and idiomatic.

Key Takeaways


  • == asks whether two objects compare equal in value; is asks whether they are the exact same object.
  • Equal contents make the first comparison true.
  • Avoid this mistake: Using is instead of == to compare strings or numbers.
Share this resourceSend this page to someone who may find it useful.