On 02/04/2010 10:26 AM, Alessandro Dentella wrote:
> Ciao,
>
> (solo) oggi mi sono imbattuto in "0 in (False,)" che ha un comportamento
> francamente controintuitivo:
>
>   In [1]: 0 in (False,)
>   Out[1]: True
>
> che a sua volta dipende dal fatto che:
>
>   In [2]: 0 == False
>   Out[2]: True
>   

Si', e' sempre stato cosi'. Anche prima che esistesse il tipo "boolean",
True e False erano interi.


> Mi viene qui di da chiedermi: ma che bisogno c'รจ che un booleano erediti da
> un intero? piace a tutti che "0 == False" sia vero?
>   

A me piace.

Mi piace meno come si comporta javascript, dove 0 == false ma 0 !==
false, quindi i tipi sono distinti, come preferisci tu.
Ma tutti gli oggetti sono true, anche l'oggetto false (*):


> >>> 0
> 0
> >>> Boolean(0)
> false
> >>> Boolean(Boolean(0))
> false
> >>> new Boolean(0)
> false {}
> >>> Boolean(new Boolean(0))
> true
> >>> new Boolean(new Boolean(0))
> true {}





(*) ovvero, l'oggetto che wrappa false. argh

-- 
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.

_______________________________________________
Python mailing list
Python@lists.python.it
http://lists.python.it/mailman/listinfo/python

Rispondere a