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-->, 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