Search code examples
pythonbraces

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


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

Solution

  • 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