Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101331
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Peter Otten <__peter__@web.de> |
| Newsgroups | comp.lang.python |
| Subject | Re: True/False value testing |
| Date | Thu, 07 Jan 2016 11:48:41 +0100 |
| Organization | None |
| Lines | 66 |
| Message-ID | <mailman.42.1452163742.2305.python-list@python.org> (permalink) |
| References | <568e3fb4$0$659$426a74cc@news.free.fr> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Trace | news.uni-berlin.de FyDCN/K9/GBnHqFyXWuJ9A2WJ8P6j5ZHZ0DWu4wbQc2g== |
| 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; 'true,': 0.04; 'context': 0.05; 'false,': 0.07; 'ast': 0.09; 'integer,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'thx': 0.09; '"is': 0.16; 'boolean': 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; 'true:': 0.16; 'wrote:': 0.16; 'string': 0.17; 'integer': 0.18; 'string,': 0.18; '>>>': 0.20; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'header:X -Complaints-To:1': 0.26; 'fine': 0.28; 'subject:/': 0.30; 'similar': 0.33; '???': 0.35; 'false': 0.35; 'but': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'equals': 0.66; 'subject:value': 0.84; 'think:': 0.84; 'subject:True': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | p57bd9a62.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:101331 |
Show key headers only | View raw
ast wrote:
> Hello
>
> For integer, 0 is considered False and any other value True
>
>>>> A=0
>>>> A==False
> True
>>>> A==True
> False
>>>> A=1
>>>> A==False
> False
>>>> A==True
> True
>
> It works fine
But not the way you think:
>>> 0 == False
True
>>> 1 == True
True
>>> 2 == True
False
>>> 2 == False
False
0 equals False, 1 equals True, and any other integer equals neither, but
"is true in a boolean context", i. e.
>>> if 42: print("42 considered true")
...
42 considered true
> For string, "" is considered False and any other value True,
> but it doesn't work
In a similar way there is no string that equals True or False, but
the empty string "" is considered false in a boolean context while all other
strings are considered true:
>>> bool("")
False
>>> bool("whatever")
True
>>>> A = ""
>>>> A==False
> False
>>>> A==True
> False
>>>> A = 'Z'
>>>> A==False
> False
>>>> A==True
> False
>
>
> What happens ???
>
> thx
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
True/False value testing "ast" <nomail@invalid.com> - 2016-01-07 11:36 +0100
Re: True/False value testing Peter Otten <__peter__@web.de> - 2016-01-07 11:48 +0100
Re: True/False value testing Chris Angelico <rosuav@gmail.com> - 2016-01-07 21:49 +1100
Re: True/False value testing Marko Rauhamaa <marko@pacujo.net> - 2016-01-07 13:19 +0200
Re: True/False value testing Chris Angelico <rosuav@gmail.com> - 2016-01-07 22:50 +1100
Re: True/False value testing Marko Rauhamaa <marko@pacujo.net> - 2016-01-07 14:07 +0200
Re: True/False value testing Chris Angelico <rosuav@gmail.com> - 2016-01-07 23:38 +1100
Re: True/False value testing "ast" <nomail@invalid.com> - 2016-01-07 12:11 +0100
csiph-web