3. Python operator

Source: Internet
Author: User
Tags bitwise

Introduction to the 3-1.python operator

1. Common operators in Python +: Add (can be a number added, or it can bestring addition, the string's + represents the concatenation of the string) -: Means minus orTake counter *: Multiply (can be multiplied by two digits, or it can bethe string is multiplied by a number, which indicates that the string repeats several times) **: A power operation, such as:2**3 represents 2 of the three-time Square) /: Except operation (when either divisor or any of the dividend is a decimal, the result of the Division also retains the decimal) //: Two numbers divided by their integral parts %: Two numbers divide to take the remaining number &: Bitwise AND (Bitwise and is the first to convert two numbers into binary number, and then bitwise AND operation, only two bits are 1 o'clock is 1such as7&18The output is 2 steps to convert the 7 and 18 respectively into 2 binary,00000111And00010010The two are then bitwise and operated on them, i.e.1 and 0 for 0,1 and 1 for 1,0 and 1 for 0It gets 00000010, which is the decimal number, which is 2.attached: Bring up the computer's own calculator, click "View" in the status bar, and then select "Programmer mode" can be directly used to calculate the number of various binary; |: Bitwise OR (A bitwise OR representation of one of them is 1, which results in 1, only 0 for both 0 o'clock) ^: Bitwise XOR OR (different or not the same, get 1, that is, 0 and 0 are 1,the same is achieved by 0, i.e. 0 and 0,1 and 1 are 0) not: Logical Non- and: Logic and or: Logical OR ~: Rollover by bit (the resulting result has aCalculation formula: ~x=-(x+1)) >>: Move right (i.e.Moves a number corresponding to the binary number to the right, the missing bit complement after moving out 0) <<: Shift Left (rule:Shift left N unitsThe resulting result in decimal is actually equal to the original number multiplied by2 of the n-th square, such as 2<<3 equals 2*2 three times, the result is 16) 2. Precedence of operators:Priority ranking is as follows:First: function invocation, addressing, subscriptSecond: Power operation * *Third: rollover operation ~Fourth: plus signFifth: *,/,%Sixth: +,-Seventh: Shift OperationEighth: Bitwise and &, bitwise OR |, bitwise XOR ^nineth: comparison operator >,<,==Tenth: not, and, or 3. Priority RuleIn general, it is left-associative, and when the assignment occurs, it is usually right-associative;

Introduction to 3-2.python expressions

Python expression differs from print execution result: the expression output preserves single quotes when it is a string, and the print output does not have single quotes

3. 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.