Learning website: https://www.runoob.com/python/pythonbasicsyntax.html
Generate notes after running code
Unfinished part:: = walrus operator not attempted
Unfinished part: operator priority not attempted
#The code is as follows:
# Chapter4: Python 3 operator print("\nchapter4:Python3 operator\n") print("1.Python The language supports the following types of operators:") print("1)Arithmetic operator") print("2)Comparison operator") print("3)Assignment Operators ") print("4)Logical operators") print("5)Bitwise Operators") print("6)member operator ") print("7)Identity operator") print("8)Operator priority") print("2.Python Arithmetic operator") print("eg:") print("The following hypothetical variables a Is 10, variable b 21:\n" " operator describe Example\n" " + plus  Add two objects a + b Output results 31\n" "  reduce  Get a negative number or a number minus another number a  b Output result 11\n" " * ride  Multiply two numbers or return a string repeated several times a * b Output result 210\n" " / except  x Divide y b / a Output result 2.1\n" " % Take die  Returns the remainder of the Division b % a Output result 1\n" " ** power  Return x Of y pow a**b To the 21st power of 10\n" " // Take integer division  take down the integer close to the divisor 9 / / 2 output 4“) print("3.Python Comparison operator") print("eg:") print("The following hypothetical variables a Is 10, variable b 20:\n" " operator describe Example\n" " == Be equal to  Compare objects for equality (a == b) Return False. \n" " != Not equal to  Compare two objects for inequality (a != b) Return True. \n" " > greater than  Return x Is it greater than y (a > b) Return False. \n" " < less than  Return x Is it smaller than y. All comparison operators return 1 for true and 0 for false. This is different from the special variable True and False Equivalence. Note the capitalization of these variable names. (a < b) Return True. \n" " >= Greater than or equal to  Return x Is greater than or equal to y. (a >= b) Return False. \n" " <= Less than or equal to  Return x Less than or equal to y. (a <= b) Return True. ") print("4.Python Assignment Operators ") print("The following hypothetical variables a Is 10, variable b 20:\n" "operator describe Example\n" "= Simple assignment operators c = a + b take a + b The operation result of is assigned as c\n" "+= Addition assignment operator c += a Equivalent to c = c + a\n" "= Subtraction assignment operator c = a Equivalent to c = c  a\n" "*= Multiplication assignment operator c *= a Equivalent to c = c * a\n" "/= Division assignment operator c /= a Equivalent to c = c / a\n" "%= Modulo assignment operator c %= a Equivalent to c = c % a\n" "**= Power assignment operator c **= a Equivalent to c = c ** a\n" "//=Take integer division assignment operator c //= a is equivalent to c = c // a\n“ ":= Walrus operator, which assigns values to variables within an expression.") print("5.Python Bitwise Operators") print("1)Bitwise operators calculate numbers as binary.") print("2)Python The bitwise algorithm in is as follows:") print("eg:") print("a = 0011 1100\n" "b = 0000 1101\n" "a&b = 0000 1100\n" "ab = 0011 1101\n" "a^b = 0011 0001\n" "~a = 1100 0011") print("Algorithm:\n" + \ "operator describe Example\n" + \ " & Bitwise and operator: two values involved in the operation,If both corresponding bits are 1,The result of this bit is 1,Otherwise it is 0. (a & b) Output result 12, binary interpretation: 0000 1100\n" + \ "  Bitwise OR operator: as long as one of the two corresponding binary bits is 1, the result bit is 1. (a  b) Output result 61, binary interpretation: 0011 1101\n" + \ " ^ Bitwise exclusive or operator: when two corresponding bits are different, the result is 1 (a ^ b) Output 49, binary interpretation: 0011 0001\n" + \ " ~ Bitwise negation operator: negates each binary bit of data,Change 1 to 0,Change 0 to 1.~x Be similar to x1 (~a ) Output result 61 ，Binary interpretation: 11000011, in the form of a signed binary number complement.\n" + \ " << Move left operator: move left several bits of each binary of the operand by\" << \"The number on the right specifies the number of moved bits. The high bit is discarded and the low bit is filled with 0. a << 2 Output 240, binary interpretation: 1111 0000\n" + \ " >> Move right operator: Set\" >> \"Each binary of the left operand is shifted several bits to the right,\" >> \"The number on the right specifies the number of digits to move a >> 2 Output result 15, binary interpretation: 0000 1111") print("6.Python Logical operators") print("Python The language supports logical operators. The following variables are assumed a For 10, b For 20:\n" "operator Logical expression describe Example\n" "and x and y Boer\"And\"  If x by False，x and y Return False，Otherwise it returns y The calculated value of. (a and b) Return to 20.\n" "or x or y Boer\"or\"  If x yes True，It returns x Otherwise it returns y The calculated value of. (a or b) Return to 10.\n" "not not x Boer\"wrong\"  If x by True，Return False . If x by False，It returns True. not(a and b) Return False") print("7.Python member operator ") print("In addition to some of the above operators, Python Member operators are also supported, and the test instance contains a series of members, including strings, lists, or tuples.\n" "operator describe Example\n" "in Returns if a value is found in the specified sequence True，Otherwise return False. x stay y In sequence , If x stay y Return in sequence True. \n" "not in If no value is found in the specified sequence, return True，Otherwise return False. x Be not in y In sequence , If x Be not in y Return in sequence True. ") print("8.Python Identity operator") print("1)Identity operators are used to compare the storage units of two objects\n" "operator describe Example\n" "is is Is to determine whether two identifiers are referenced from one object x is y, Similar id(x) == id(y) , Returns if the same object is referenced True，Otherwise return False\n" "not is not Whether two identifiers refer to different objects x is not y ， Similar id(a) != id(b). Returns the result if the referenced object is not the same True，Otherwise return False. ") print("2)is And == Difference: is Used to determine whether two variable reference objects are the same, == Used to determine whether the values of reference variables are equal.") print("9.Python Operator priority") print("1)The following table lists all operators from the highest to the lowest priority:\n" "operator describe\n" "** index (Highest priority)\n" "~ +  Flip by bit, One yuan plus sign and minus sign (The last two methods are called +@ and @)\n" "* / % // Multiply, divide, remainder, and divide \ n“ "+  addition and subtraction\n" ">> << Shift right, shift left operator\n" "& position 'AND'\n" "^  Bitwise Operators\n" "<= < > >= Comparison operator\n" "== != equal operator \n" "= %= /= //= = + = * = * * = assignment operator \ n“ "is is not Identity operator\n" "in not in member operator \n" "not and or Logical operators") print("2)Pyhton3 No longer support <> Operators, you can use the != replace")
#Operation result:
Chapter4: Python 3 operator
1.Python supports the following types of operators:
1) Arithmetic operator
2) Comparison operator
3) Assignment operator
4) Logical operators
5) Bitwise operator
6) Member operator
7) Identity operator
8) Operator priority
2.Python arithmetic operators
eg:
The following assumes that variable a is 10 and variable b is 21:
Operator description instance
+Add  add two objects a + b output result 31
Minus  gets a negative number or one minus another a  b output  11
*Multiply  multiply two numbers or return a string repeated several times a * b output result 210
/Divide  x b y y b / a output 2.1
%Modulo  returns the remainder of Division B% a output result 1
**Power return x to the 21st power of 10
//Take integer division  take down the integer close to the divisor 9 / / 2 output 4
3.Python comparison operator
eg:
The following assumes that variable a is 10 and variable b is 20:
Operator description instance
==Equal  Returns False if the comparison object is equal (a == b).
! = not equal  returns True when comparing whether two objects are not equal (a! = b).
>Greater than  Returns whether x is greater than y (a > b) and returns False.
< less than  Returns whether x is less than y. All comparison operators return 1 for True and 0 for False. This is equivalent to the special variables True and False, respectively. Note the capitalization of these variable names. (a < b) returns True.
>=Greater than or equal to  Returns whether x is greater than or equal to y. (a > = b) returns False.
< = less than or equal to  Returns whether x is less than or equal to y. (a < = b) returns True.
4.Python assignment operator
The following assumes that variable a is 10 and variable b is 20:
Operator description instance
=A simple assignment operator c = a + b assigns the result of a + b to C
+=Addition assignment operator c += a is equivalent to c = c + a
=Subtractive assignment operator c = a is equivalent to c = c  a
*=Multiplication assignment operator c *= a is equivalent to c = c * a
/=Division assignment operator c /= a is equivalent to c = c / a
%=Modular assignment operator c% = a is equivalent to C = C% a
**=Power assignment operator c **= a is equivalent to c = c ** a
//=Take the integer division assignment operator c //= a, which is equivalent to c = c // a
: = walrus operator, which can assign values to variables within an expression.
5.Python bit operators
1) Bitwise operators calculate numbers as binary.
2) The bitwise algorithm in Python is as follows:
eg:
a = 0011 1100
b = 0000 1101
a&b = 0000 1100
ab = 0011 1101
a^b = 0011 0001
~a = 1100 0011
Algorithm:
Operator description instance
&Bitwise and operator: two values involved in the operation. If both corresponding bits are 1, the result of this bit is 1. Otherwise, 0 (A & B) output result 12, binary interpretation: 0000 1100
Bitwise OR operator: as long as one of the two corresponding binary bits is 1, the result bit is 1. (a  b) output result 61, binary interpretation: 0011 1101
^Bitwise exclusive or operator: when two corresponding binary bits are different, the result is 1 (a ^ b) output result 49, binary interpretation: 0011 0001
~Bitwise negation operator: reverses each binary bit of data, i.e. changes 1 to 0 and 0 to 1. ~x is similar to  x1 (~ a) output result  61, binary interpretation: 11000011, in the complement form of a signed binary number.
< left move operator: the binary bits of operands are all shifted to the left by several bits. The number to the right of "< is used to specify the number of bits to move. The high bit is discarded and the low bit is filled with 0. A < 2 output result 240, binary interpretation: 1111 0000
>>Move right operator: move all the binary bits of the left operand to the right several bits, and the number on the right specifies the number of bits to move. A > > 2 output result 15, binary interpretation: 0000 1111
6.Python logical operators
Python language supports logical operators. The following assumption is that variable a is 10 and variable B is 20:
Operator logical expression description instance
And x and y Boolean and  if x is False, x and y returns False, otherwise it returns the computed value of y. (a and b) return to 20.
Or x or y Boolean or  if x is True, it returns the value of X, otherwise it returns the computed value of y. (a or b) return to 10.
Not not x Boolean not  Returns False if x is True. If x is False, it returns True. not(a and b) returns False
7.Python member operator
In addition to some of the above operators, Python also supports member operators. The test case contains a series of members, including strings, lists, or tuples.
Operator description instance
In returns True if a value is found in the specified sequence, False otherwise. X in the y sequence, if x returns True in the y sequence.
Not in returns True if no value is found in the specified sequence, False otherwise. X is not in the y sequence and returns True if x is not in the y sequence.
8.Python identity operator
1) Identity operators are used to compare the storage units of two objects
Operator description instance
Is is to determine whether two identifiers are referenced from an object x is y, similar to id(x) == id(y). If the same object is referenced, True will be returned, otherwise False will be returned
Not is not to determine whether two identifiers are referenced from different objects x is not y, similar to ID (a)! = ID (b). Returns True if the referenced object is not the same, False otherwise.
2) Difference between is and = = is used to determine whether two variable reference objects are the same, and = = is used to determine whether the value of the reference variable is equal.
9.Python operator priority
1) The following table lists all operators from the highest to the lowest priority:
Operator description
**Index (highest priority)
~+  Flip by bit, one dollar plus sign and minus sign (the last two methods are named + @ and  @)
 /% / / multiply, divide, remainder and divide


addition and subtraction

< shift right, shift left operator
&Bit 'AND'
^ bit operator
Comparison operator
==! = equals operator
=% = / = / / / =  = + = * = * * = assignment operator
is is not identity operator
in not in member operator
not and or logical operator
2)Pyhton3 no longer supports the < > operator, you can use! = instead