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.
Related Posts:
- Single quotes vs. double quotes in Python
- TypeError: ‘NoneType’ object is not iterable in Python
- TypeError: ‘NoneType’ object is not iterable in Python
- Best way to return multiple values from a function? [closed]
- Iterate through a C++ Vector using a ‘for’ loop
- Python NoneType object is not callable (beginner)
- Iterate through a C++ Vector using a ‘for’ loop
- Why do I get AttributeError: ‘NoneType’ object has no attribute ‘something’?
- Iterate through a C++ Vector using a ‘for’ loop
- TypeError: ‘NoneType’ object is not iterable in Python
- not None test in Python
- What are the most common Python docstring formats?
- How to “test” NoneType in python?
- Using true and false in C
- What is PEP8’s E128: continuation line under-indented for visual indent?
- What is a ‘NoneType’ object?
- Simple way to create matrix of random numbers
- Styling multi-line conditions in ‘if’ statements?
- Line is too long. Django PEP8
- How do I copy a file in Python?
- Could not install packages due to a “Environment error :[error 13]: permission denied : ‘usr/local/bin/f2py'”
- ^=, -= and += symbols in Python
- How does numpy.newaxis work and when to use it?
- “If not” condition statement in python
- How to move a file in Python?
- Round a floating-point number down to the nearest integer?
- beyond top level package error in relative import
- How can I sort a dictionary by key?
- How do you append to a file?
- sklearn error ValueError: Input contains NaN, infinity or a value too large for dtype(‘float64’)
- Jupyter Notebook not saving: ‘_xsrf’ argument missing from post
- What does it mean to have an index to scalar variable error? python
- Could not install packages due to an EnvironmentError:
- What does “e” in “1e-5” in Python language mean and what is the name of this notation?
- How to avoid “RuntimeError: dictionary changed size during iteration” error?
- TypeError: generatecode() takes 0 positional arguments but 1 was given
- python – if not in list
- syntaxError: ‘continue’ not properly in loop
- How to get the ASCII value of a character
- How do I set the figure title and axes labels font size in Matplotlib?
- Why do people write #!/usr/bin/env python on the first line of a Python script?
- How to raise a numpy array to a power? (corresponding to repeated matrix multiplications, not elementwise)
- How to know the version of pip itself
- Microsoft Visual C++ 14.0 is required (Unable to find vcvarsall.bat)
- How to import other Python files?
- Python TypeError: not enough arguments for format string
- Python virtualenv questions
- How to activate virtualenv in Linux?
- Open file in a relative location in Python
- Python – TypeError: Object of type ‘int64’ is not JSON serializable
- Python add item to the tuple
- How to print a dictionary’s key?
- Python setup.py develop vs install
- Selenium using Python – Geckodriver executable needs to be in PATH
- Spark RDD to DataFrame python
- index 1 is out of bounds for axis 0 with size 1
- How can I time a code segment for testing performance with Pythons timeit?
- Python: tuple indices must be integers, not str when selecting from mysql table
- AttributeError: ‘list’ object has no attribute ‘replace’
- Understanding NumPy’s einsum
- For loop and ‘numpy.float64’ object is not iterable error
- What are the causes of overflow encountered in double_scalars besides division by zero?
- Creating a dictionary from a csv file?
- How can I check for NaN values?
- Bad operand type for unary +: ‘str’
- How do I get the parent directory in Python?
- How to fix: “UnicodeDecodeError: ‘ascii’ codec can’t decode byte”
- AttributeError: ‘Tensor’ object has no attribute ‘_keras_history’
- pip install -r requirements.txt [Errno 2] No such file or directory: ‘requirements.txt’
- Zsh: Conda/Pip installs command not found
- Find the nth occurrence of substring in a string
- How to convert ‘binary string’ to normal string in Python3?
- What is the meaning of curly braces?
- Copy a list of list by value and not reference
- How do I print bold text in Python?
- python3 TypeError: ‘function’ object is not iterable
- pip connection failure: cannot fetch index base URL http://pypi.python.org/simple/
- NaN loss when training regression network
- Building multi-regression model throws error: `Pandas data cast to numpy dtype of object. Check input data with np.asarray(data).`
- TypeError: ‘set’ object does not support indexing
- Python 3.6 No module named pip
- Difference between import tkinter as tk and from tkinter import
- Split function add: \xef\xbb\xbf…\n to my list
- ImportError in importing from sklearn: cannot import name check_build
- Root mean square of a function in python
- NameError: name ‘python’ is not defined
- What is an easy way to implement fprintf in python?
- What is the recommended way to use Vim folding for Python code
- Plotting a python dict in order of key values
- How to normalize a NumPy array to within a certain range?
- How to check if a user is logged in (how to properly use user.is_authenticated)?
- Python ‘while’ with two conditions: “and” or “or”
- How to pass a list by reference?
- Python Quicksort Runtime Error: Maximum Recursion Depth Exceeded in cmp
- “for loop” with two variables?
- Python webbrowser.open() to open Chrome browser
- Flatten nested dictionaries, compressing keys
- Sending posts from Python to WordPress
- i want to run python script in wordpress
- How do you fetch the authors email or IP from /comments? (REST API)