#Python算术运算符主要分为比较, assignment, arithmetic, bitwise operations, members, identities, logical #算术运算符式例 "" + Plus-two objects added-minus two objects subtract * multiply-two numbers multiplied/divide-two numbers divide by% modulo-returns the remainder of the division * power- Returns the Y-power/divide-Division of X-the integer portion of the return quotient "" "A, B, c=10,20,0 C = B + a print ("B+a ="C" ;") c = a-b print ("a-b="C" ;") C = b * A print ("B*a="C" ;") C = b//a print ("gets an integer similar to the divisible in Java: b//a"C" ;") c = b/a print ("Take a number of floating-point types: b/a="C" ;") C = b% a print ("Get the rest of the Java-like operation: B%a"C""" = = equals-Compare objects for equality!= is not equal to-compare two objects for unequal> Greater-Returns whether x is greater than Y< less-Returns whether x is less than Y. All comparison operators return 1 to represent true, and 0 to represent false. This is equivalent to the special variable true and false respectively. Note that these variable names are capitalized. >= greater than or equal-returns whether X is greater than or equal to Y. <= is less than or equal to-returns whether X is less than or equal to Y. """ if(A = = B): print ("a equals B")Else: Print ("A is not equal to B")if(a!= B): Print ("A is not equal to B")Else: Print ("a equals B")if(A < B): print ("A is less than B")elif(a==b): Print ("a equals B")Else: Print ("A is greater than B")if(A > B): Print ("A is greater than B")elif(a==b): Print ("a equals B")Else: Print ("A is less than B")""" assignment operator= simple assignment operator+ = addition Assignment operator- = subtraction assignment operator*= multiplication Assignment operator/= Division assignment operator%= modulus assignment operator**= Power assignment operator//= The divide-by assignment operator""" c = A + b print (The value of A + B is: ", c) + + a print (The value of "C + a" is: ", c) C *= a print (The value of "C * a" is: ", c) C/= a print ("C/A value is:", c) C **= 2 print (The value of "c * * 2 is:", c) C%= a print (The value of "C% a" is: "Cif(c==0): c = a+1 C//= a print (The value of "C/A" is: "C""" & Bitwise AND Operator: Two values that participate in the operation, if two corresponding bits are 1, the result of this bit is 1, otherwise 0| Bitwise OR operator: As long as the corresponding two binary has one 1 o'clock, the result bit is 1. ^ Bitwise XOR: When two corresponding binary differences, the result is 1~ bitwise inverse operator: each bits of the data is reversed, which turns 1 to 0, and 0 to 1. ~x is similar to-x-1. << left move operator: The operands of an operand are all shifted left several digits, and the number of digits to the right of the "<<" specifies the number of bits to be moved, the high drop, and the low fill 0. >> Right Move operator: shifts all the digits of the operand to the left of ">>" to the right of several bits, and the number to the right of ">>" specifies the number of digits to move""" A = 0011 = 1100 b = 0000 1101 c = 0 c = A & B; # a = 0000 1100 print ("A & B value is:", c) C = A | b # 0011 = 1101 Print ("a | The value of B is: ", c) C = a ^ b; # 0011 = 0001 print ("The value of a ^ B is:", c) C = ~a; # -61 = 1100 0011 Print ("~a value is:", c) C = a << 2; # 1111 = 0000 print ("The value of a << 2 is:", c) C = a >> 2; # = 0000 1111 Print ("The value of a >> 2 is:"C""" logical Operatorsand X and y Boolean "and"-if x or Y returns False for false,x and yor X or y boolean "or"-if x or Y is True, it returns the value of x, otherwise it returns the calculated value of Y. (A or B) returns 10. not not X expression Boolean "non"-returns False if the x expression is True. If the x expression is False, it returns True""" # Modify the value of variable a =Trueb =Falseif(A andb): Print ("Both variables A and B are true")Else: Print ("Variables A and B have one that is not true")if(Aorb): Print ("Both variables A and B are true, or one of the variables is true")Else: Print ("Both variables A and B are not true")if not(A andb): Print ("Both variables A and B are false, or one of the variables is false")Else: Print ("Both variables A and B are true")if not(Aorb): Print ("Both variables A and B are not true")Else: Print ("Both variables A and B are true, or one of the variables is true")""" member OperatorsIn if the value found in the specified sequence returns TRUE, False is returned otherwise. x in the y sequence, if X returns True in the y sequence. not in if the value is not found in the specified sequence returns TRUE, False is returned. """ A = ten b = List = [1, 2, 3, 4, 5];if(A inList): Print ("1-variable A in the given list")Else: Print ("1-variable A is not in the list given")if(b not inList): Print ("2-variable B is not in the list given.")Else: Print ("2-variable B in the given list")""" identity operatoris to determine whether two identifiers are referenced from an object x is Y, similar to ID (x) = = ID (y), return True If the same object is referenced, or Falseis isn't is to determine whether two identifiers are referenced from different objects""" A = b = 20if(A isb): Print ("1-a and B have the same identity")Else: Print ("1-a and b do not have the same identity")if(ID (a) = = ID (b)): Print ("2-a and B have the same identity")Else: Print ("2-a and b do not have the same identity") # Modify the value of variable B = 30if(A isb): Print ("3-a and B have the same identity")Else: Print ("3-a and b do not have the same identity")if(A is notb): Print ("4-a and b do not have the same identity")Else: Print ("4-a and B have the same identity")''' Summary:Priority level:* * Index (highest priority)~ +-Bitwise flip, unary Plus and minus (last two methods named +@ and-@)*/%//multiply, divide, modulo and divide+-Addition subtraction>> << Move right, left operator& ' and ' ^ | bitwise operators<= < > >= = =!= comparison operator=%=/=//= = = + *= **= assignment operatorIs are not identity operatorIn the not in member operatorNot OR and logical operators'''
#运行结果: B+a = 30 ;
a-b= -10 ;
B*a= 200 ; The
gets an integer similar to the division in Java: b//a 2 ;
The number of a floating-point type is taken: B/a= 2.0 ;
Get a similar Java: b%a 0
a is not equal to B
a is not equal to B
a is less than B
a less than B
A + B of the value of: the
C + A value is: 40 The value of
C * A is: C/A
is: 40.0
C * * 2 value is: 1600.0
C% A value is: 0.0
C/A value is: 1
A & B values are:
A | The value of B is: The value of a ^ B is: -61 the value of a << 2 is: ~a
a >> 2 has a value of:
variables A and B have a Not true
Both variables A and B are true, or one of the variables is true
variables A and B are false, or one of the variables is false
both variables A and B are true, or one of the variables is true
1 -Variable A is not in the given list
2-variable B is not in the given list
1-a and B have the same identity
2-a and B have the same identity
3-a and b do not have the same identity
4 -A and B do not have the same identity