Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk2 min

How to Check if a Variable Is None in Python: `is None` vs `== None`

Use `is None` to check for Python’s None singleton and `is not None` to check its absence. Learn why `== None`, truthiness checks, and pandas missing-value tests answer different questions.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use value is None to check whether a Python variable refers to None, and value is not None for the inverse. Do not use == None for this check: equality can be customized, while identity expresses the singleton check directly.

Check for None with identity

None is Python’s singleton null object. The is operator tests whether two references point to the same object, so value is None directly answers whether value refers to that object.

if value is None:
    print("no value was provided")

if value is not None:
    use(value)

PEP 8 says: “Comparisons to singletons like None should always be done with is or is not, never the equality operators.” It also recommends is not None rather than the less readable not ... is None. See PEP 8.

Why not use == None?

== asks whether two values are equal. A class can define its own equality behavior with __eq__, so value == None may invoke code that does not mean “is this the None singleton?” Identity operators cannot be customized. Python’s data model documentation describes these comparison behaviors.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

For a None check, is None makes the intended question explicit and avoids depending on an object’s equality implementation.

None is not the same as a false value

If you need to know whether an optional value was supplied, test it against None. A truthiness check asks a different question and skips valid values that evaluate to false, such as 0, False, an empty string, an empty list, or an empty dictionary.

# Accepts 0, False, and empty containers when they are valid values
if value is not None:
    use(value)

# Runs only when value is truthy
if value:
    use(value)

Use if value: only when you want truthiness, not when you want to distinguish None from other values. PEP 8 explicitly cautions against confusing these intentions.

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

For pandas data, use its missing-value checks

is None checks for the Python None object; it does not test every missing-data marker used in libraries. pandas also supports sentinels such as NaN, NaT, and pd.NA, whose equality behavior is not a reliable general missingness test. For pandas data, use isna() or notna(); pandas documents that these methods also treat None as missing. See the pandas missing-data guide.

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

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair 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.