Difference Between is and == in Python

When I build Python automation scripts, I often need to check whether a value exists before processing it. A report field may contain None, a list may hold the same data twice, or two variables may point to one shared object.

This is where many Python beginners mix up is and ==. They look similar, but they answer two completely different questions.

By the end of this guide, you will know exactly when to use each operator and how to avoid comparison bugs in real Python code.

Difference Between is and == in Python

The key difference between is and == in Python comes down to identity versus value.

  • Use == to check whether two values are equal.
  • Use is to check whether two variables refer to the same object in memory.

An object is any value Python creates and stores, such as a string, list, number, dictionary, or custom class instance.

Here is the simplest comparison:

first_status = "completed"
second_status = "completed"

print(first_status == second_status)
print(first_status is second_status)

The == operator checks whether both variables contain the same text. The is operator checks whether both names point to one object.

You should not rely on the second result for strings. Python may reuse some strings internally, but that behavior depends on the Python version and runtime details. Use == when you compare text values in a local script, server application, data analysis notebook, or automation workflow.

If you are still getting comfortable with Python values and variables, review how to use Python variables.

How == Works in Python

The equality operator == compares the contents or logical values of two objects. This makes it the operator you will use most often.

For example, imagine a small reporting script that reads a department name from a CSV file and decides where to save the report.

department = "Finance"

if department == "Finance":
print("Saving the finance report")
else:
print("Saving the general report")

You can see the output in the screenshot below.

Difference Between is and == Python

This code compares the value inside department with "Finance". Both strings contain the same characters, so the condition returns True.

Comparing numbers, strings, and lists

You can use == with common Python data types.

print(25 == 25)
print("Admin" == "Admin")
print([10, 20, 30] == [10, 20, 30])

All three comparisons return True. Python compares matching values, characters, or elements.

For lists, Python checks each item in order. Two separate lists can contain identical values, even though Python stores them as separate objects.

morning_tasks = ["download", "clean", "export"]
evening_tasks = ["download", "clean", "export"]

print(morning_tasks == evening_tasks)
print(morning_tasks is evening_tasks)

The first line returns True because both lists contain the same items. The second line returns False because Python created two different list objects.

This distinction matters when you work with lists in data-cleaning scripts. For example, you may want to remove duplicates from a Python list based on values, not memory locations.

Equality in custom classes

A class is a blueprint that defines objects. By default, custom objects compare by identity unless you define how equality should work.

class Report:
def __init__(self, name):
self.name = name

report_one = Report("Monthly Sales")
report_two = Report("Monthly Sales")

print(report_one == report_two)

This returns False. The objects contain the same report name, but Python sees two separate objects.

You can define the __eq__ method to tell Python how to compare two Report objects.

class Report:
def __init__(self, name):
self.name = name

def __eq__(self, other):
return self.name == other.name

report_one = Report("Monthly Sales")
report_two = Report("Monthly Sales")

print(report_one == report_two)

You can see the output in the screenshot below.

Difference Between is and == in Python

Now the result is True because the class compares the name values. This approach helps when you build larger applications with custom objects, models, or configuration classes.

Learn more about constructors in Python when you start creating your own classes.

How is Works in Python

The identity operator is checks whether two variable names point to the same object.

Here is a practical example from a log-processing script:

report_config = {
"file_name": "sales_report.csv",
"include_headers": True
}

active_config = report_config

print(active_config is report_config)

This returns True because active_config does not create a new dictionary. It points to the same dictionary as report_config.

Now change one value through active_config.

active_config["file_name"] = "weekly_sales.csv"

print(report_config["file_name"])

The output is:

weekly_sales.csv

Both variables reference one dictionary, so a change through either variable affects the same object.

Copying creates a different object

If you need a separate dictionary, create a copy.

report_config = {
"file_name": "sales_report.csv",
"include_headers": True
}

backup_config = report_config.copy()

print(backup_config == report_config)
print(backup_config is report_config)

The first comparison returns True because both dictionaries have equal content. The second returns False because .copy() creates another dictionary object.

This concept becomes important when you work with nested data. A shallow copy duplicates only the outer object, while nested lists and dictionaries may still point to shared objects. Read this guide on shallow copy vs deep copy in Python before copying complex configuration data.

Pro Tip: I have found that is bugs often appear after someone assigns one list or dictionary to another variable and expects an independent copy. If you plan to edit the new variable, use .copy() for a simple structure or copy.deepcopy() for nested data.

The Best Use Case for is: Checking None

In day-to-day Python development, use is most often when you check for None.

None represents the absence of a value. A function may return None when it does not find a record, receives missing input, or cannot calculate a result.

def get_report_owner(report_id):
owners = {
101: "Anika",
102: "Ravi"
}
return owners.get(report_id)

owner = get_report_owner(103)

if owner is None:
print("No report owner found")
else:
print(f"Report owner: {owner}")

You can see the output in the screenshot below.

Difference Between Python is and ==

This code checks whether the function returned the one shared None object. Python keeps one None object, so identity comparison fits perfectly.

You can also write:

if owner is not None:
print(f"Report owner: {owner}")

Use is not None when you specifically want to confirm that a value exists.

Do not write this:

if owner == None:
print("No report owner found")

It may work in simple cases, but is None clearly states your intent and avoids unexpected behavior with custom objects.

The same idea appears in checking and removing None values from a Python list.

Why You Should Not Use is for Values

Many developers try is with integers or strings because the result sometimes looks correct.

first_number = 100
second_number = 100

print(first_number is second_number)

This may return True in some Python environments. Python often reuses small integer objects to save memory. It may also reuse certain strings.

That behavior does not make is a value-comparison operator.

first_number = 1000
second_number = 1000

print(first_number == second_number)
print(first_number is second_number)

The equality comparison should return True because both values equal 1000. The identity comparison may return False because Python can create separate objects for those values.

A script that uses is for numbers may work on your laptop and fail after a Python upgrade, code change, or deployment to a server.

Use == whenever you compare:

  • Numbers
  • Strings
  • Lists
  • Tuples
  • Dictionaries
  • Boolean values
  • User input
  • Values from files, APIs, databases, or forms

For example, if you collect user input, compare the text value with ==. See how to use the input function in Python for practical examples.

is vs == in a Real Script

Let’s combine both operators in a small automation example. This script checks a report status before it processes a file.

report_status = "ready"
report_path = None

if report_status == "ready":
print("The report is ready for processing")

if report_path is None:
print("No report file has been selected")

The first condition compares a string value, so == is correct. The second condition checks whether the variable has no value, so is None is correct.

Here is a slightly more realistic version:

def process_report(report_name, report_path):
if report_path is None:
return "Choose a report file before processing."

if report_name == "":
return "Enter a report name."

return f"Processing {report_name} from {report_path}"

message = process_report("Weekly Sales", None)
print(message)

The function uses is None to detect missing file information. It uses == "" to detect an empty string. These values represent different situations, so they need different checks.

If you work with file automation, this pairs well with checking whether a file exists in Python.

Things to Keep in Mind

  • Use == for values: Compare text, numbers, lists, tuples, and dictionaries with the equality operator.
  • Use is None: Check missing values with is None or is not None, not == None.
  • Do not trust integer results: Python may reuse small integers, but that implementation detail should never drive your comparison logic.
  • Copy mutable objects carefully: Lists and dictionaries can share one object after assignment, so use .copy() when you need separate data.
  • Watch custom classes: Define __eq__ when your class needs meaningful value comparisons.
  • Avoid identity checks in data processing: Values loaded from CSV, JSON, Excel, APIs, or databases should almost always use ==.

Frequently Asked Questions

What is the main difference between is and == in Python?

== compares values, while is compares object identity. Use == when two values should match and is when both variables must point to the same object.

Should I use is or == for strings in Python?

Use == for strings. Python may reuse some string objects, but you should never depend on that behavior for a string comparison.

Why does 100 is 100 sometimes return True?

Python may reuse small integer objects as an optimization. This result does not mean that is compares numbers correctly, so always use == for numeric comparisons.

Why should I use is None instead of == None?

None is a singleton, which means Python creates one shared None object. is None clearly checks for that object and avoids custom equality behavior.

Can I use is to compare two lists in Python?

Use is only when you need to know whether both variables reference the same list object. Use == when you need to check whether two lists contain the same items.

What does is not mean in Python?

is not checks whether two variables do not point to the same object. You will commonly use it as value is not None to confirm that a variable contains a value.

The difference between is and == becomes simple once you separate object identity from value equality. Use == for almost every normal comparison, and reserve is for None checks or cases where shared object identity genuinely matters.

I hope you found this article helpful and can now write cleaner Python comparisons with confidence.

You May Also Like

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.