How to work out the -(-(-(.... part in this code snippet?

57 Views Asked by At

I am not looking for the answer for this code, but I would like to know how to do the working out in the -(-(-(-2))) ... part.

I tried looking it up on Google "Python negative braces.." etc etc but nothing.

-(-(-(-2))) == -2 and 4 >= 16 ** 0.5
2

There are 2 best solutions below

1
On BEST ANSWER

What this means is essentially negative negative negative negative 2. So because a negative of a negative a positive, this is equal to positive 2.

So in the end: -(-(-(-2))) == -2 is False, so if you include that as part of an and, you will get False no matter what:

>>> -(-(-(-2))) == -2 and True
False
0
On

That works exactly the same way it would in ordinary mathematical notation. -(anything) is the negation of whatever is in the parentheses. The negation of 2 is -2, and the negation of -2 is 2.

-(-2) is the negation of -2, which is 2.

-(-(-2)) is the negation of -(-2). -(-2) is 2, and the negation of that is -2.

-(-(-(-2))) is the negation of -(-(-2)). -(-(-2)) is -2, and the negation of that is 2.