Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101337
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: True/False value testing |
| Date | 2016-01-07 23:38 +1100 |
| Message-ID | <mailman.45.1452170304.2305.python-list@python.org> (permalink) |
| References | <568e3fb4$0$659$426a74cc@news.free.fr> <mailman.43.1452163794.2305.python-list@python.org> <877fjl7i30.fsf@elektro.pacujo.net> <mailman.44.1452167431.2305.python-list@python.org> <871t9t7fup.fsf@elektro.pacujo.net> |
On Thu, Jan 7, 2016 at 11:07 PM, Marko Rauhamaa <marko@pacujo.net> wrote: > However, I *could* find this statement: > > 1. [or] is a short-circuit operator, so it only evaluates the second > argument if the first one is False. > > 2. [and] is a short-circuit operator, so it only evaluates the second > argument if the first one is True. > > <URL: https://docs.python.org/3/library/stdtypes.html#boolean-op > erations-and-or-not> > > The wording is very unfortunate (both the use of the word "is" and the > explicit references to the builtin constants False and True). Actually, that's a good point. I would call that a docs error. The definition of the comparison operators is, more or less: 1) Call a.__lt__(b). If it doesn't return NotImplemented, that's the value. 2) Call b.__gt__(a). If it doesn't return NotImplemented, that's the value. 3) Raise TypeError. Massively simplified; steps 1 and 2 get switched around if b is a subclass of a, and there's stuff about slots, and so on. But that's basically it. The function is allowed to return anything it likes. The built-in types generally return instances of bool, but custom classes are free to generalize (as numpy has done to great effect). ChrisA
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