python--operator

Source: Internet
Author: User

1. Arithmetic Operation:

2. Comparison operation:

3. Assignment Operation:

4, bit operation:

Note: ~ Example: 6 Explanation: Multiply the binary number +1 by-1, i.e. ~x =-(X+1),-(101 + 1) = 110

A bitwise reversal can only be used in front of a number. So writing 3+~5 can get the result-3, it's wrong to write a.

5. Logical Operation:

and annotations:

    1. In Python, and and or to perform Boolean logic calculations, as you would expect, but they do not return Boolean values, but instead return one of the values they actually compare.
    2. The value of a left-to-right calculus expression in a Boolean context, and returns the last value if all the values in the Boolean context are true.
    3. If a value in the Boolean context is False, and returns the first false value

or annotations:

    1. When using or , the left-to-right calculus is evaluated in a Boolean context, just like and. If a value is true,or returns the value immediately
    2. If all values are false,or returns the last False value
    3. Note that or in a Boolean context, the expression calculus continues until the first true value is found, and then the remaining comparison values are ignored

And-or used in combination:

    1. Combining the two preceding grammars, reasoning can be.
    2. To enhance the readability of the program, it is best to be associated with parentheses, for example:
      (1 and ' X ') or ' Y '

6. Member Arithmetic:

7. Identity operations

8. Operator Precedence: top-down, high-to-low priority

python--operator

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.