There's no performance difference, as they compile to the same bytecode:

>>> import dis
>>> dis.dis("not x is None")
  1           0 LOAD_NAME                0 (x)
              2 LOAD_CONST               0 (None)
              4 COMPARE_OP               9 (is not)
              6 RETURN_VALUE
>>> dis.dis("x is not None")
  1           0 LOAD_NAME                0 (x)
              2 LOAD_CONST               0 (None)
              4 COMPARE_OP               9 (is not)
              6 RETURN_VALUE

Stylistically, I try to avoid not x is y, a human reader might misunderstand it as (not x) is y. If I write x is not y then there is no ambiguity.

Answer from Daniel Stutzbach on Stack Overflow
Top answer
1 of 9
1325

There's no performance difference, as they compile to the same bytecode:

>>> import dis
>>> dis.dis("not x is None")
  1           0 LOAD_NAME                0 (x)
              2 LOAD_CONST               0 (None)
              4 COMPARE_OP               9 (is not)
              6 RETURN_VALUE
>>> dis.dis("x is not None")
  1           0 LOAD_NAME                0 (x)
              2 LOAD_CONST               0 (None)
              4 COMPARE_OP               9 (is not)
              6 RETURN_VALUE

Stylistically, I try to avoid not x is y, a human reader might misunderstand it as (not x) is y. If I write x is not y then there is no ambiguity.

2 of 9
445

Both Google and Python's style guide is the best practice:

if x is not None:
    # Do something about x

Using not x can cause unwanted results.

See below:

>>> x = 1
>>> not x
False
>>> x = [1]
>>> not x
False
>>> x = 0
>>> not x
True
>>> x = [0]         # You don't want to fall in this one.
>>> not x
False

You may be interested to see what literals are evaluated to True or False in Python:

  • Truth Value Testing

Edit for comment below:

I just did some more testing. not x is None doesn't negate x first and then compared to None. In fact, it seems the is operator has a higher precedence when used that way:

>>> x
[0]
>>> not x is None
True
>>> not (x is None)
True
>>> (not x) is None
False

Therefore, not x is None is just, in my honest opinion, best avoided.


More edit:

I just did more testing and can confirm that bukzor's comment is correct. (At least, I wasn't able to prove it otherwise.)

This means if x is not None has the exact result as if not x is None. I stand corrected. Thanks bukzor.

However, my answer still stands: Use the conventional if x is not None. :]

🌐
Medium
medium.com › @Hichem_MG › check-if-a-variable-is-not-none-in-python-3d6407798dec
Check if a variable is not None in Python | Medium
June 13, 2024 - While `is not None` is the most explicit and clear way to check for non-None values, there are alternative approaches. In Python, non-None objects are generally considered truthy.
Discussions

Is there any downside of using if x / if not x versus if x is None / if x is not None ?
It depends how strict you need to be with your variable. An empty list also counts as "False" but is not None. More on reddit.com
🌐 r/learnpython
18
7
October 8, 2024
Why is "not None" true?
Because None is essentially the same as “False” (not entirely, but we call them Falsy value) print(not []) or print(not “”) would also output true, as you’re basically reversing the False Boolean value with the ‘not’ operator More on reddit.com
🌐 r/PythonLearning
6
8
January 25, 2025
What's the most pythonic way of checking if variable is None or empty string ""?
Both None and "" are falsy values so simply if not variable: will cover both those cases. This doesn't explicitly check for those values but if you're just checking for something not being set this is probably the way to go. More on reddit.com
🌐 r/learnpython
9
4
July 6, 2021
What's the difference between != and is not?
To take a non programming approach, suppose you and I both have a $50 bill. They are of equal value but are not the same as their serial numbers differ. So they are equivalent but not identical. In Python, == checks for equivalency. For custom classes you can implement this yourself. In contrast, is and is not checks to see if two things are identical. Generally it's used to check if two variable names are aliases of each other and to check for None as there is only NoneType instance. More on reddit.com
🌐 r/learnpython
119
332
April 7, 2020
🌐
Python.org
discuss.python.org › ideas
Syntactic Sugar for 'is not None' - Ideas - Discussions on Python.org
June 4, 2022 - The following construct occurs very frequently: if item is not None: process_item(item) else: error_handling() With longer functions, this causes a readability conundrum: Option 1: Leave it as is but introduce a double negation (if not ... else), ...
🌐
sebhastian
sebhastian.com › python-not-none
Python 'is not none' syntax explained | sebhastian
January 12, 2023 - To conclude, the is not None syntax is a way to check if a variable or expression is not equal to None in Python.
🌐
W3Schools
w3schools.com › python › python_none.asp
Python None
None is a special constant in Python that represents the absence of a value. Its data type is NoneType, and None is the only instance of a NoneType object. Variables can be assigned None to indicate "no value" or "not set".
🌐
Note.nkmk.me
note.nkmk.me › home › python
None in Python | note.nkmk.me
May 10, 2023 - In Python, None is an instance of NoneType. a = None print(a) # None print(type(a)) # <class 'NoneType'> ... It represents the absence of a value. For example, a function that does not explicitly return a value with return will return None.
🌐
GeeksforGeeks
geeksforgeeks.org › python › what-is-the-difference-between-is-none-and-none
What is the difference between "is None" and "== None"? - GeeksforGeeks
November 19, 2024 - None in Python lies in how they compare values. is None checks for identity which means it checks if the object itself is None whereas == None checks for equality which means it checks if the value of the object is equal to None.
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › is there any downside of using if x / if not x versus if x is none / if x is not none ?
r/learnpython on Reddit: Is there any downside of using if x / if not x versus if x is None / if x is not None ?
October 8, 2024 -

I prefer the former because it's obviously shorter... reads better. Also, I can check whether a collection or a string is empty the same way (because it checks whether x evaluates to False).

I think the only disadvantage might be for variables of type e.g. int | None and when program's behaviour must be different for value 0 and for None. In such case, obviously, one should use if x is None.

🌐
Bobby Hadz
bobbyhadz.com › blog › python-check-if-none
Check if a Variable is or is not None in Python | bobbyhadz
Since there is only one instance of None in a Python program, the correct way of checking for None is to use the is operator. ... Copied!var_1 = None if var_1 is None: print('The variable is None') print(var_1 is None) # 👉️ True · Similarly, ...
🌐
DEV Community
dev.to › hichem-mg › how-to-check-if-variable-is-not-none-in-python-f5o
How to check if variable is not None in Python - DEV Community
June 13, 2024 - In Python, None is a special constant representing the absence of a value or a null value. It is an object of its own datatype, the NoneType. Checking if a variable is not None is a common task in Python programming, essential for ensuring that ...
🌐
Python Tutorial
pythontutorial.net › home › advanced python › python none
Python None
March 27, 2025 - print(None == None) print(None is None)Code language: Python (python) ... It’s a good practice to use the is or is not operator to compare a value with None.
🌐
Quora
quora.com › Can-you-explain-in-simple-terms-what-is-not-None-in-Python-3-x-is
Can you explain in simple terms what 'is not None' in Python 3.x is? - Quora
Answer (1 of 3): Let's say you have a variable. Call it x since I'm not feeling very creative. You set it to None. So, you do this: > if x: And your statement will be False. If you set x to 5, it will be True. In many cases this will do what you're expecting However, there are other cases whe...
🌐
LabEx
labex.io › tutorials › python-how-to-check-if-a-variable-is-not-none-in-python-559607
How to Check If a Variable Is Not None in Python | LabEx
The output will show that my_variable is not None after each assignment. Save the explore_none.py file. ... This exercise demonstrates that None is a specific value and that any other value, including integers, strings, and booleans, is considered a non-None value. Understanding this distinction is essential for writing conditional statements and handling different types of data in Python.
🌐
Python Morsels
pythonmorsels.com › none
None in Python - Python Morsels
January 22, 2024 - Python's None value is used to represent nothingness. None is the default function return value.
🌐
W3Schools
w3schools.com › python › ref_keyword_none.asp
Python None Keyword
Python Examples Python Compiler ... Python Interview Q&A Python Bootcamp Python Training ... The None keyword is used to define a null value, or no value at all. None is not the same as 0, False, or an empty strin...
🌐
Python Guides
pythonguides.com › check-if-a-variable-is-not-none-in-python
Check if a Variable Is Not None in Python
December 1, 2025 - In Python, None is a special constant that represents the absence of a value or a null value. It’s an object of its own datatype called NoneType. When a variable is assigned None, it means it has no meaningful data. If you try to operate on a variable without confirming it’s not None, your ...
🌐
Parseltongue
parseltongue.co.in › the-proper-way-to-check-for-none-in-python
ParselTongue - The Proper Way to Check for None in Python
November 15, 2024 - If you need to check if a variable is specifically None, use is None or is not None. This approach ensures that only the None object is targeted, leading to more readable and predictable code.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-check-nonetype-in-python
How to check NoneType in Python - GeeksforGeeks
June 30, 2025 - is operator is the most Pythonic way to check for None, as it tests identity. Since None is a singleton, this method is accurate, efficient and preferred in conditionals and return checks. ... Explanation: x is None checks if x refers to None.
🌐
Real Python
realpython.com › null-in-python
Null in Python: Understanding Python's NoneType Object – Real Python
December 15, 2021 - That is, the NoneType class only ever gives you the same single instance of None. There’s only one None in your Python program: ... Even though you try to create a new instance, you still get the existing None. You can prove that None and my_None are the same object by using id(): ... Here, the fact that id outputs the same integer value for both None and my_None means they are, in fact, the same object. Note: The actual value produced by id will vary across systems, and even between program executions.