Operator priority,

Source: Internet
Author: User

Operator priority,

1 >>> a = 20 2 >>> B = 15 3 >>> c = 10 4 >>> d = 5 5 >>>> e = 0 6 >>> e = (a-B) * c/d 7 >>> print (e) 8 10 9 >>> print ('(a-B) * c/d', e) 10 (a-B) * c/d 10.011 >>> print (a-B) * c/d, e) 12 10.0 10.013 >>>> e = a-B * c/d14 >>> print (e) 15-10.016 # brackets are included in the brackets, without parentheses. multiply and divide the brackets first, plus or minus 17 # Brackets have the highest priority
1 >>> e = a + B + c-c * d2 >>> print (e) 3-54 >>> e = (a + B + c) -c * d5> print (e) 6-57 # No brackets are added for the preceding input. The expression itself is normal, but it is not intuitive. For example, if brackets are added, it looks relatively intuitive. The running results are the same, but you can see the execution sequence of the expression at a glance.

 

1> 2 ** 1 + 2 2 4 3> 2 ** (1 + 2) 4 8 5> 2 ** 2*3 6 12 7> 2 ** (2*3) 8 64 9 # The multiplication party has an advanced priority, there are brackets first calculated parentheses, no parentheses, first calculate the Multiplication Side; 10 11> a + B * c-d12 16513> a * B/c + d14 3515 # The multiplication priority is the same, and higher than the addition and subtraction with the same priority; 16 17 >>> a + B-c + d18 3019 >>>> a + b-c-d20 2021 # When the priority is the same, evaluate the value in the order from left to right.


End

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.