[Tutor] Defining "bit" type -- why not '!' ?

Alan Gauld alan.gauld at btinternet.com
Thu Jan 29 13:22:29 CET 2009


"spir" <denis.spir at free.fr> wrote

> Here is an overal and a trial to introduce my view on this topic.
...
> * The mix of "extended logic" on non-logical types and treating 
> integers
>    as bit sequences provakes a kind of conceptual collision.
> * As a solution, bitwise operations may apply only to a type (byte 
> or int)
>    on which "extended logic" raises an TypeError.

You are probably correct but it would break a ton of working code!
Especially when you recall that bool types were only introduced
relatively recently so a lot of old code relies on the fact that
True/False were until then literally 1/0.

Maybe it is "improved" in Python 3. As you say the ~ operator
makes most sense if applied to bytes only. But for compatibility
reasons I suspect they have kept it as-is...

Alan G 




More information about the Tutor mailing list