Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #79528
| From | Alain Ketterlin <alain@dpt-info.u-strasbg.fr> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Truthiness |
| Date | 2014-10-23 16:47 +0200 |
| Organization | Universites Paris VI/Paris VII - France |
| Message-ID | <87bnp23ksg.fsf@dpt-info.u-strasbg.fr> (permalink) |
| References | <61f0b04c-b827-4c03-b55d-4d5bd85b56f6@googlegroups.com> |
Simon Kennedy <sffjunkie@gmail.com> writes:
> Just out of academic interest, is there somewhere in the Python docs where the following is explained?
>
>>>> 3 == True
> False
>>>> if 3:
> print("It's Twue")
>
> It's Twue
>
> i.e. in the if statement 3 is True but not in the first
https://docs.python.org/2/reference/compound_stmts.html#the-if-statement
says: "The if statement [...] selects exactly one of the suites by
evaluating the expressions one by one until one is found to be true (see
section Boolean operations for the definition of true and false)"
and then:
https://docs.python.org/2/reference/expressions.html#booleans
says: "In the context of Boolean operations, and also when expressions
are used by control flow statements, the following values are
interpreted as false: False, None, numeric zero of all types, and empty
strings and containers (including strings, tuples, lists, dictionaries,
sets and frozensets). All other values are interpreted as true."
(links are to the 2.7 version of the reference manual, I think not much
has changed in 3.* versions.)
-- Alain.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Truthiness Simon Kennedy <sffjunkie@gmail.com> - 2014-10-23 07:30 -0700
Re: Truthiness Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-23 08:45 -0600
Re: Truthiness Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-24 11:42 +1100
Re: Truthiness Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2014-10-23 16:47 +0200
Re: Truthiness Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2014-10-23 17:01 +0200
Re: Truthiness Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-23 16:07 +0000
Re: Truthiness Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2014-10-23 16:49 +0200
Re: Truthiness Skip Montanaro <skip.montanaro@gmail.com> - 2014-10-23 09:51 -0500
Re: Truthiness Simon Kennedy <sffjunkie@gmail.com> - 2014-10-23 07:56 -0700
Re: Truthiness random832@fastmail.us - 2014-10-23 11:24 -0400
csiph-web