Python Learning--operator explanation

Source: Internet
Author: User
Tags arithmetic operators bitwise bitwise operators logical operators

First, Introduction

The 1.python operator is divided into

    • Arithmetic operators
    • Compare (relational) operators
    • Assignment operators
    • logical operators
    • Bitwise operators
    • Member operators
    • Identity operator
    • Operator Precedence

2. Priority of Operations

  

**index (highest priority)~ +-Bitwise rollover, unary Plus and minus (the last two methods are called [email protected] and-@)*  /   %   //multiply, divide, modulo, and divide+   -Addition Subtraction>> <<shift right, left shift operator& Bit' and'^   |Bitwise Operators<= < > >=comparison Operators<> = = =equals operator=    %=   /=   //=   -=   +=   *=   **=Assignment Operators is       is  notidentity operatorinch      not inchmember Operators not     and     orlogical operators

3. Detailed examples

" "bitwise OPERATORS: operator bitwise operators by numeric values on each bit of the binary: & | ^ ~ << >>" "Print(True &True)#Bitwise & converts 10 binary to binary and then binary per bit operation 1 1 for 1 The rest is 0 .Print('2:', Bin (2)) Print('8:', Bin (8))#2 0010#8#Ten 1010#0 0000Print(2&8)Print(10&8)#| Bitwise OR as long as 1 is 1#Ten 01010#10100#11110 2+4+8+16Print(10|20)#^ xor difference is 1 the same as 0#Ten 01010#10100Print(10^20)#8 01000#11100#10100Print(8^28)#~ to reverse 0 for 1 1 for 0#001# the#4 0100#1011-5#-8 +2#Print (Bin ( -5))Print(To)#0101#1010Print(The Bin ())#010000#101111-32 +8+4+2+1Print(~16)#left shift number of moved << moving digits right shift number of moves >> move number of digits#1010#Move left 1010000Print(10<<3)#1010#Move right 0001Print(10>>3)#2^3#010# +Print(2<<2)" "------------------------------------------------------------logical operator BOOL and BOOL, BOOL or BOOL, not bool" "a= 20; B=30FL=a>10 andB<50Print(FL)Print(a>50orB>10)Print(a>10orB<50)Print( notA>10)Print( notA>30 andB>10)Print(a>20 andA<30orA<50 )#logical operator precedence not and ORPrint(a<=20 and(a<30orA<50) )" "---------------------------------------------------------------operator Extension" "a=2b=2.0Print(A isb)Print(a==b)Print("--------------------------------------------------------------------") A=0b=0a=1010888800b=1010888800Print(A isb)Print(2**8)#2^8Print(2**64) A=18446744073709551618b=18446744073709551618Print(A isb)

Operation Result:

e:\python_vs_code\directory[directory]>d://py3.6//python.exe e:/python_vs_code/directory[directory]/demo0731/py_ Typeid.pytrue2: 0B108: 0b100008303020-2-0b110-178018  Truetruetruefalsetruetruetruefalsetrue-------------------------------------------------------------------- true25618446744073709551616true

Note: In the operator: (Inverse operation: take what number, the number is negative and minus one )

On the command line > two integers greater than 28, which is two of the eight parties, ' is ' for flase, ' = = ' is True

In the script file > No matter how big the number is, true

"ispoints to memory address

= = points to the variable value "

Python Learning--operator explanation

Related Article

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.