How to modify meaning of builtin function "not" to "!"?
Ivan Voras
ivoras at __fer.hr__
Fri May 9 09:54:16 EDT 2008
grbgooglefan wrote:
> I am creating functions, the return result of which I am using to make
> decisions in combined expressions.
> In some expressions, I would like to inverse the return result of
> function.
>
> E.g. function contains(source,search) will return true if "search"
> string is found in source string.
> I want to make reverse of this by putting it as:
> if ( ! contains(s1,s2) ):
> return 1
>
> I found that "!" is not accepted by Python & compile fails with
> "invalid syntax".
> Corresponding to this Boolean Operator we've "not" in Python.
>
> How can I make "not" as "!"?
"not" is a perfectly valid boolean operator in Python and means just
what "!" means in C. The equivalent binary operator is "~", just like in C.
>>> print not True
False
>>> print not 1
False
>>> print not 0
True
>>> print ~1
-2
>>> print ~0
-1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20080509/56bcb71b/attachment-0001.sig>
More information about the Python-list
mailing list