PEP 312 (and thus 308) implemented with a black magic trick

Alex Martelli aleax at
Tue Mar 18 16:07:10 CET 2003

Erik Max Francis wrote:
> Furthermore, if you change the meaning of ~, what operator now becomes
> used to represent bitwise negation?

Why, the
"operator", of course -- or the
"operator", as a roughly equivalent alternative -- after all,

    assert ~x == -1^x == -1-x

innit...?  Using ^ has the advantage of raising TypeError when ~ would
(I think), while - would be more permissive.


More information about the Python-list mailing list