Operator Precedence** → priority of operators (which runs first)
Order of execution:
-
()→ highest priority -
**→ power -
*,/,% -
+,- -
==, !=, >, > =, <, >=
-
not -
and -
or→ lowest priority
example
result = 10 + 5 * 2
print(result) # 10 + (5*2) = 10 + 10 = 20
result = (10 + 5) * 2
print(result) # (10+5) * 2 = 15 * 2 = 30
result = 2 ** 3 * 2
print(result) # (2**3) * 2 = 8 * 2 = 16
result = True or False and False
print(result) # True or (False and False) = Trueoutput
20
30
16
TrueNote
()can change the priorityandruns beforeor- Always use
()if you want clear and predictable results