Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #101868

Re: "x == None" vs "x is None"

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Ben Finney <ben+python@benfinney.id.au>
Newsgroups comp.lang.python
Subject Re: "x == None" vs "x is None"
Date Mon, 18 Jan 2016 13:46:42 +1100
Lines 39
Message-ID <mailman.83.1453085214.15297.python-list@python.org> (permalink)
References <n7fo7q$dso$1@news2.informatik.uni-stuttgart.de> <mailman.57.1453025729.15297.python-list@python.org> <n7fshb$f36$1@news2.informatik.uni-stuttgart.de> <CAPTjJmrDZCiDLmRtiukDv2Z1Gz69fz3+_4xYeu-PoXBdC3dtGg@mail.gmail.com> <CAJ4+4aoHHzFJNHvw+LjimO6qHr6dsUskMsQw6y+uiW0jrQzm-w@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
X-Trace news.uni-berlin.de 6tGHFE0SRN1cGRecBXioYgbehHViAmLXo85UMm7lhJOQ==
Cancel-Lock sha1:lIcho6Kyv+QyOUJ8MX6vgufC4/4=
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'matches': 0.07; 'none)': 0.07; '``none``': 0.09; '``none``,': 0.09; 'behave': 0.09; 'confuse': 0.09; 'definition,': 0.09; 'differently.': 0.09; 'logic': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:None': 0.09; 'python': 0.10; 'useful,': 0.13; 'value.': 0.15; 'camp': 0.16; 'none).': 0.16; 'null.': 0.16; 'occur.': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'libraries': 0.22; 'null)': 0.22; 'programming': 0.22; 'header :User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'defining': 0.27; 'object,': 0.27; 'this.': 0.28; 'comparison': 0.29; "i'm": 0.30; 'compared': 0.30; 'operations': 0.31; 'null': 0.33; 'quite': 0.35; 'but': 0.36; 'there': 0.36; 'subject:" ': 0.36; 'to:addr:python-list': 0.36; 'really': 0.37; 'two': 0.37; 'say': 0.37; 'received:org': 0.37; 'data': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; '_o__)': 0.84; 'obtain.': 0.84; 'received:125': 0.84; 'time.\xe2\x80\x9d': 0.84; 'dennis': 0.91; 'misleading': 0.91; '1988': 0.93
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host jigong.madmonks.org
X-Public-Key-ID 0xAC128405
X-Public-Key-Fingerprint 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405
X-Public-Key-URL http://www.benfinney.id.au/contact/bfinney-pubkey.asc
X-Post-From Ben Finney <bignose+hates-spam@benfinney.id.au>
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:101868

Show key headers only | View raw


<paul.hermeneutic@gmail.com> writes:

> I prefer (x is None) and (x is not None).

There are good reasons to prefer this.

But this is not a good reason:

> This matches the SQL concept of NULL.

That's not really helpful, because it *doesn't* match.

> (X = NULL) is not valid since NULL is not a value and cannot be
> compared with anything.

SQL Null fails comparison with any value. Python ``None`` is a value and
can be compared like any other value.

SQL Null is neither truthy nor falsy; three-value logic is required when
Null can occur. Python ``None`` is falsy by definition, and two-value
(Boolean) logic continues to obtain.

SQL Null is not a value and has no data type. Python ``None`` is an
object and, like any other object, has a type defining the operations
that it can perform.

And so on. While some libraries do conflate SQL Null with Python
``None``, the two concepts really behave quite differently. It is
needlessly misleading to say they “match” in any sense.

I'm in the camp that says, while SQL is quite useful, its NULL is a wart
<URL:https://dba.stackexchange.com/questions/5222/why-shouldnt-we-allow-nulls/6049>.

-- 
 \        “… it's best to confuse only one issue at a time.” —Brian W. |
  `\    Kernighan and Dennis M. Ritchie, _The C programming language_, |
_o__)                                                             1988 |
Ben Finney

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

"x == None" vs "x is None" Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2016-01-17 09:51 +0000
  Re: "x == None" vs "x is None" Chris Angelico <rosuav@gmail.com> - 2016-01-17 21:15 +1100
    Re: "x == None" vs "x is None" Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2016-01-17 11:05 +0000
      Re: "x == None" vs "x is None" Peter Otten <__peter__@web.de> - 2016-01-17 12:26 +0100
      Re: "x == None" vs "x is None" Chris Angelico <rosuav@gmail.com> - 2016-01-17 22:29 +1100
      Re: "x == None" vs "x is None" <paul.hermeneutic@gmail.com> - 2016-01-17 11:01 -0700
      Re: "x == None" vs "x is None" Random832 <random832@fastmail.com> - 2016-01-17 16:33 -0500
      Re: "x == None" vs "x is None" Chris Angelico <rosuav@gmail.com> - 2016-01-18 08:38 +1100
      Re: "x == None" vs "x is None" Ben Finney <ben+python@benfinney.id.au> - 2016-01-18 13:46 +1100
  Re: "x == None" vs "x is None" fernando junior <fernandojr.ifcg@live.com> - 2016-01-19 14:20 -0800

csiph-web