Describes the priority of operators in Python.

Source: Internet
Author: User
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

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.