Understanding the working mechanis of python unary arithmetic operators.

hongy...@gmail.com hongyi.zhao at gmail.com
Sat Oct 2 04:34:15 EDT 2021


See the following testings:

In [24]: a=3.1415926535897932384626433832795028841971
In [27]: -a
Out[27]: -3.141592653589793

In [28]: +a
Out[28]: 3.141592653589793

In [17]: ~-+1
Out[17]: 0

In [18]: -~+1
Out[18]: 2

In [19]: -+~1
Out[19]: 2

In [20]: +~-1
Out[20]: 0

I'm very puzzled by these operators. Any hints will be highly appreciated.

Regards,
HZ



More information about the Python-list mailing list