This article mainly introduces the priority of operators used in Python, which is the basic knowledge of Python learning. If you need a friend, you can refer to the operator priority to determine the grouping in the condition expression. This affects how an expression is computed. Some operators have higher priority than others. For example, multiplication operators have higher priority than addition operations.
For example, x = 7 + 3*2. Here, x is assigned a value of 13 instead of 20. Because the operator * has a higher priority than +, it is first multiplied by 3*2 and then added to 7.
Here, operators with the highest priority appear above the table, and those with the lowest priority appear at the bottom. In an expression, a higher priority operator is calculated first.
For example:
Try the following example to understand the operator priority available in the Python programming language:
#! /Usr/bin/pythona = 20b = 10c = 15d = 5e = 0e = (a + B) * c/d # (30*15) /5 print "Value of (a + B) * c/d is", ee = (a + B) * c)/d # (30*15) /5 print "Value of (a + B) * c)/d is", ee = (a + B) * (c/d); # (30) * (15/5) print "Value of (a + B) * (c/d) is", ee = a + (B * c)/d; #20 + (150/5) print "Value of a + (B * c)/d is", e
When the above program is executed, it will produce the following results:
Value of (a + B) * c/d is 90 Value of (a + B) * c)/d is 90 Value of (a + B) * (c/d) is 90 Value of a + (B * c)/d is 50