Operator precedence to determine the grouping in an expression of a condition. This affects how an expression is evaluated. Some operators have precedence over others, for example, the multiplication operator has a higher precedence than the addition operation.
For example x=7 + 2; Here, X is assigned a value of 13 instead of 20 because the operator * has a higher priority than +, so it is first multiplied by 3 * 2 and then added 7.
Here, the highest precedence operator appears above the table, with the lowest displayed at the bottom. In an expression, the higher precedence operator is evaluated first.
For example:
Try the following example to understand the operator precedence that the Python programming language can choose:
#!/usr/bin/pythona = 20b = 10c = 15d = 5e = 0e = (A + b) * C/D # (+ *)/5print "Value of (A + B) * C/D is", EE = ((a + b) * c)/d # ($ *)/5print "Value of ((A + b) * C)/d is", EE = (A + b) * (C/D); # (15/5) print "Value of (A + B) * (C/D) is", EE = a + (b * c)/D; # + (150/5) print "Value of A + (b * c)/d is", E
When executing the above program, it produces the following result:
Value of (A + B) * C/D is 90Value of ((A + b) * C)/d are 90Value of (A + B) * (C/D) is 90Value of A + (b * c)/D-is 50