Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk2 min

`is None` vs `== None` in Python: What’s the Difference?

Use `is None` to test for Python’s None singleton. `== None` invokes equality behavior that a class can customize.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use value is None (or value is not None) to check whether a value is Python’s None singleton. value == None performs an equality comparison instead, and a value’s type can customize that comparison. For a singleton check, Python’s guidance is to use identity, not equality.

What is the difference between is None and == None?

Expression What it asks Can a type customize the result? Use it for
x is None Is x the one None object? No. Identity operators cannot be customized. Checking whether a value is None.
x == None Does x compare equal to None? Yes. The type can define equality behavior. Equality comparisons in general; it is not the recommended None check.

Python has a single None object, so a value assigned None is identical to it. The Python 3.14.7 expression reference says that PEP 8 advises comparisons for singletons should use is or is not, never equality operators.

Why can == None behave differently?

The == operator performs equality comparison. Python maps x == y to the rich comparison method x.__eq__(y), which a class can customize. That method may even return a value other than True or False; when the result is used as a condition, Python converts it to a Boolean.

For example, a class can define equality so that one of its instances compares equal to None, even though the instance is not the None object. By contrast, is asks only whether both references point to the same object. The Python data model documentation describes rich comparisons and __eq__; the default object.__eq__ behavior uses identity when a class has not supplied its own equality method.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How should you check for None?

Check whether a result is missing

result = lookup(key)

if result is None:
    handle_missing_result()

This condition tests exactly whether result is the None singleton.

Check whether a value is present

if value is not None:
    use(value)

Use is not None for the inverse check. It is still an identity test, not a general test of whether the value is useful or non-empty.

Why not use if not value?

if not value checks truthiness, not whether a value is None. It also treats values such as 0, '', and empty containers as false. If those are valid values and only None means “absent,” use an explicit identity check so the condition does not reject them.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When should you use == or is?

Use == to compare values, such as strings, integers, or ordinary containers. Use is when the question is whether two references identify the same object—especially for None. Object identity is not generally guaranteed to correspond to value equality, so is is not a substitute for == on ordinary data.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The same singleton-checking principle applies to other singleton sentinels such as NotImplemented, as noted in the Python expression reference. The Python Programming FAQ likewise explains that two variables assigned None are guaranteed to be identical because None is a singleton.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.