Python Data operations

Source: Internet
Author: User

Arithmetic operations:

a=10b=20Print(A+B)#AddPrint(A-B)#SubtractionPrint(A*B)#multiplicationPrint(b/a)#DivisionPrint((b+2)%a)#Find remainderPrint(b**a)#Power SquarePrint(b//a)#take an integer#------------------------------------------------results are as follows:30-102002.02102400000000002

Comparison operation:

Assignment operation:


Logical operation:

Member Operations:

Identity operation:

Bit operations:

Calculates the smallest unit of representation for a bits calculation stored in the smallest unit of a bits (bit) 8bit=byte(bytes) 1024x768byte=1kbyte takes eight bits (bit). A= -bits, as follows: -     -     +     -    8    4    2    1------------------------------0    0    1    1    1    1    0    0= -b= -bits, as follows: -     -     +     -    8    4    2    1------------------------------0    0    0    0    1    1    0    1= -a&B by Location (and), both true values are the result, and the result is as follows: -     -     +     -    8    4    2    1-------------------------------0    0    1    1    1    1    0    0= -0    0    0    0    1    1    0    1= --------------------------------0    0    0    0    1    1    0    0= Aa|B bitwise OR (OR), two have one true, the result is true, as follows: -     -     +     -    8    4    2    1-------------------------------0    0    1    1    1    1    0    0= -0    0    0    0    1    1    0    1= --------------------------------0    0    1    1    1    1    0    1= Aa^b Bitwise XOR (^), the same as 0, the difference is 1, as follows -     -     +     -    8    4    2    1-------------------------------0    0    1    1    1    1    0    0= -0    0    0    0    1    1    0    1= --------------------------------0    0    1    1    0    0    0    1= the~a Bitwise Inversion (~), the result is reduced by 256, as a result.  -     -     +     -    8    4    2    1-------------------------------0    0    1    1    1    1    0    0= -0    0    0    0    1    1    0    1= --------------------------------1    1    0    0    0    0    1    1=195 195- the= - A(Result) a<< left move operator,a<<2move two bits. as follows: -     -     +     -    8    4    2    1-------------------------------0    0    1    1    1    1    0    0= --------------------------------1    1    1    1    0    0    0    0= -<--move two bits, rear less than 0.a>> Right Move operator,a>>2move two bits. as follows: -     -     +     -    8    4    2    1-------------------------------0    0    1    1    1    1    0    0= --------------------------------0    0    0    0    1    1    1    1= the--&GT, shift right two bits, empty part 0
A = 60#= 0011 1100b = 13#= 0000 1101c =0c= A & B;#0000 1100Print("Line 1-value of C is", c) C= A | b#1101 = 0011Print("Line 2-value of C is", c) C= a ^ b;#0001 = 0011Print("Line 3-value of C is", c) C= ~a;#-61 = 1100 0011Print("Line 4-value of C is", c) C= a << 2;#0000 = 1111Print("Line 5-value of C is", c) C= a >> 2;#= 0000 1111Print("Line 6-value of C is"C

Results:

 is    are -61is       The processhas ended, exit code 0  

Operator Precedence:

More content can be accessed:

Http://www.runoob.com/python/python-operators.html

Python Data operations

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.