This article mainly introduces the use of Python operators in the priority, is the basic knowledge of Python learning, the need for friends can refer to the
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 + 3* 2; here, X is assigned 13, not 20, because the operator * has a higher precedence than +, so it is multiplied by 3 * 2 First, then plus 7.
Here, the highest precedence operators appear above the table, those with the lowest display 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 from:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#!/usr/bin/python A = b = ten c = d = 5 E = 0 E = (A + b) * C/D # (m)/5 print "Value of (A + b) * C/ D is ", e E = ((A + b) * c)/D # (m)/5 print" Value of ((A + b) * C)/d is ", e E = (A + b) * (C/D); # (15/5) print "Value of (A + B) * (C/D) is", e E = a + (b * c)/D; # + (150/5) print "Value of A + (b * c)/d is", E |
When the above program is executed, it produces the following results:
?
1 2 3 4 |
Value of (A + B) * C/D is-value of ((A + b) * C)/d is-value of (A + B) * (C/D) is value of a + (b * c)/d is 50 |
Note < : More Wonderful tutorials please focus on the triple Programming