A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2002-October/029125.html below:

[Python-Dev] the not operator (and the __not__ special method)

[Python-Dev] the not operator (and the __not__ special method)Brian Quinlan brian@sweetapp.com
Thu, 03 Oct 2002 14:50:54 -0700
> shows that python doesn't call the __not__ special method
> in a 'not' operator statement.

Python calls the special __nonzero__ method so check the truth value of
an object.

> Another question, I notice than  "a or b" and "a and b" are
> not equivalent to "a | b" and "a & b", since the last ones call
> the methods __or__ and __and__ if they are defined, but
> the "literal forms" never call them.  Is this intentional?, if
> that is the case, I guess a big and clear note is needed
> in the documentation.

"and" and "or" are logical operators, while "|" and "&" are bitwise
operators. 

>>> 13 & 14
12
>>> 13 and 14
14

> And just for symmetry considerations, given that python has the
> pairs (and, &) and (or, |), does anybody considering to introduce
> the ! operator, so you can have the equivalent (not, !) too?

There is a bitwise not operator: ~

>>> ~2
-3

Cheers,
Brian




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4