[Python] 0 in (False,) // 0 == False

Marco Mariani marco.mariani a prometeia.it
Gio 4 Feb 2010 12:30:21 CET


On 02/04/2010 12:25 PM, Alessandro Dentella wrote:

> Questa però non mi pare la risposta a "che bisogno c'è". Che non è una
> domana oziosa, è che immagino che ci *sia* bisogno in un modo che io ora non
> colgo. La domanda rifrasata sarebbe forse: quali sono le caratteristiche di
> un booleano che derivano da un intero?
>
> Riprendendo la tua risposta: che bisogno c'è che sia il più piccolo tipo
> *numerico* che porta informazione?
>   

Questo e' il pronunciamento di Guido al riguardo:

http://www.python.org/dev/peps/pep-0285/

6) Should bool inherit from int?

    => Yes.

       In an ideal world, bool might be better implemented as a
       separate integer type that knows how to perform mixed-mode
       arithmetic.  However, inheriting bool from int eases the
       implementation enormously (in part since all C code that calls
       PyInt_Check() will continue to work -- this returns true for
       subclasses of int).  Also, I believe this is right in terms of
       substitutability: code that requires an int can be fed a bool
       and it will behave the same as 0 or 1.  Code that requires a
       bool may not work when it is given an int; for example, 3 & 4
       is 0, but both 3 and 4 are true when considered as truth
       values.



-- 
This e-mail (and any attachment(s)) is strictly confidential and for use only by intended recipient(s). Any use, distribution, reproduction or disclosure by any other person is strictly prohibited. The content of this e-mail does not constitute a commitment by the Company except where provided for in a written agreement between this e-mail addressee and the Company. If you are not an intended recipient(s), please notify the sender promptly and destroy this message and its attachments without reading or saving it in any manner. Any non authorized use of the content of this message constitutes a violation of the obligation to abstain from learning of the correspondence among other subjects, except for more serious offence, and exposes the person responsible to the relevant consequences.



Maggiori informazioni sulla lista Python