Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101846
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Peter Otten <__peter__@web.de> |
| Newsgroups | comp.lang.python |
| Subject | Re: "x == None" vs "x is None" |
| Date | Sun, 17 Jan 2016 12:26:45 +0100 |
| Organization | None |
| Lines | 37 |
| Message-ID | <mailman.58.1453030018.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> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Trace | news.uni-berlin.de gzASFEWBPzYeOkrg5+lEvgUUupdyOlxIE/mSerZYYJBw== |
| 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.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; 'none)': 0.07; '"if': 0.09; 'check.': 0.09; 'none"': 0.09; 'precedence': 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; 'jan': 0.11; 'times,': 0.13; '"is': 0.16; '"is"': 0.16; '"not"': 0.16; '2016': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.16; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'chris': 0.26; 'right.': 0.27; 'url:python': 0.33; 'false': 0.35; 'url:dev': 0.35; 'but': 0.36; 'should': 0.36; 'url:org': 0.36; 'evaluation': 0.36; 'subject:" ': 0.36; 'url:library': 0.36; 'to:addr:python- list': 0.36; 'pm,': 0.36; 'received:org': 0.37; 'several': 0.38; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'term': 0.60; 'within': 0.64; 'places': 0.64; '(is': 0.84; 'not)': 0.84; 'url:reference': 0.91; 'why?': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | p57bd8da5.dip0.t-ipconnect.de |
| User-Agent | KNode/4.13.3 |
| 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:101846 |
Show key headers only | View raw
Ulli Horlacher wrote: > Chris Angelico <rosuav@gmail.com> wrote: >> On Sun, Jan 17, 2016 at 8:51 PM, Ulli Horlacher >> <framstag@rus.uni-stuttgart.de> wrote: >> > I have seen at several places "x == None" and "x is None" within >> > if-statements. >> > What is the difference? >> > Which term should I prefer and why? >> >> tl;dr: Prefer "x is None" as a check. > > And for the negation? > "if not x is None" or "if x is not None" > > I have seen the last one several times, but i do not understand it, > because: > >>>> x=0 >>>> x is not None > True >>>> not None > True >>>> x is True > False - "is" has higher precedence than "not" - "is not" is an operator in its own right. So the evaluation is not (x is None) x (is not) None https://docs.python.org/dev/library/stdtypes.html#comparisons https://docs.python.org/dev/reference/expressions.html#operator-precedence
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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