Precedence in Python when operators are used

Source: Internet
Author: User
Tags in python

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.