Operator priority,
1 >>> a = 20 2 >>> B = 15 3 >>> c = 10 4 >>> d = 5 5 >>>> e = 0 6 >>> e = (a-B) * c/d 7 >>> print (e) 8 10 9 >>> print ('(a-B) * c/d', e) 10 (a-B) * c/d 10.011 >>> print (a-B) * c/d, e) 12 10.0 10.013 >>>> e = a-B * c/d14 >>> print (e) 15-10.016 # brackets are included in the brackets, without parentheses. multiply and divide the brackets first, plus or minus 17 # Brackets have the highest priority
1 >>> e = a + B + c-c * d2 >>> print (e) 3-54 >>> e = (a + B + c) -c * d5> print (e) 6-57 # No brackets are added for the preceding input. The expression itself is normal, but it is not intuitive. For example, if brackets are added, it looks relatively intuitive. The running results are the same, but you can see the execution sequence of the expression at a glance.
1> 2 ** 1 + 2 2 4 3> 2 ** (1 + 2) 4 8 5> 2 ** 2*3 6 12 7> 2 ** (2*3) 8 64 9 # The multiplication party has an advanced priority, there are brackets first calculated parentheses, no parentheses, first calculate the Multiplication Side; 10 11> a + B * c-d12 16513> a * B/c + d14 3515 # The multiplication priority is the same, and higher than the addition and subtraction with the same priority; 16 17 >>> a + B-c + d18 3019 >>>> a + b-c-d20 2021 # When the priority is the same, evaluate the value in the order from left to right.
End