Why are parentheses needed sometimes and not others?


#1

I was stuck on this forever. I originally did not include parentheses in bool_four and bool_five Why were they needed? Especially in bool_five which is so similar to bool_one?

bool_one = 7 > 8 and 10 > 11 is False

bool_two = -(-(-(-2))) == -2 and 4 >= 16**0.5 is False

bool_three = 19 % 4 != 300 / 10 / 10 is False

bool_four = (-(1**2) < 2**0 and 10 % 10 <= 20 - 10 * 2) is True

bool_five = (8 > 7 and 11 > 10) is True


#2

@stevenjgunter,
https://docs.python.org/2/reference/expressions.html
Read 5.15. Operator precedence
and
read 5.9. Comparisons

# evaluation between PARENTHESES-( ) is done first
print  (8 > 7 and 11 > 10) is True # gives a True
print   8 > 7 and 11 > 10 is True  # gives a False
#The operators is and is not test for object identity:
#     x is y is true if and only if x and y are the same object. 
#     x is not y yields the inverse truth value
#     the =is= operator is evaluated BEFORE the =and= operator
print 11 > 10 is True  # gives False because =not the same object=