Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ben Finney 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: References: 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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:101868 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 . -- \ “… 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