Numeric operators (+, -, *, /, %, **, //)
Python There are the following operators .
+a # Integers
-a # negative
a + b # Add
a - b # Subtraction
a * b # Multiplication
a / b # division
a % b # remainder
a ** b # Exponentiation
a // b # Divide and round
An operator (~, &, |, ^, <<, >>)
The following operators are defined
~a # Bit reversal
a & b # AND: And (a And b All are 1 When is 1)
a | b # OR: Logic or (a or b by 1 The result is 1)
a ^ b # XOR: Logical XOR
a << b # Move left
a >> b # Move right
Substitution operator (=, +=, -=, *=, /=, %=, **=, //=, &=, |=, ^=, <<=, >>=)
There are the following substitution operators . I won't support it ++ and -- , Replace it with a += 1 and a -= 1 Express .
a = b # towards a Plug in b
a += b # a = a + b
a -= b # a = a - b
a *= b # a = a * b
a /= b # a = a / b
a %= b # a = a % b
a **= b # a = a ** b
a //= b # a = a // b
a &= b # a = a & b
a |= b # a = a | b
a ^= b # a = a ^ b
a <<= b # a = a << b
a >>= b # a = a >> b
Comparison operator (==, !=, <, >, <=, >=, <=>, ===)
There are the following comparison operators
a == b # a and b equal
a != b # a and b Unequal
a < b # a Than b Small
a > b # a Than b Big
a <= b # a Less than or equal to b
a >= b # a Greater than or equal to b
a <> b # a It's not equal to b
a is b # a And b equal
a is not b # a And b Unequal
a in b # a Included in b
a not in b # a Not included in b
Boolean operation (and, or, not)
There are the following operators .
a and b # a And b
a or b # a or b
not a # Not a
Conditional operator (if else)
The following formula ,c When true, the result is x , Otherwise, the result is y..
x if c else y
String operators (+, *, [n:m])
The string contains the following operators .n and m Specify a negative number , Count from the end of the text .
a + b # String splicing
a * n # a Duplicate string n Time
a[n] # Take out No n Characters
a[n:m] # From n To the first m Substring of
a[n:] # The first n Substrings from beginning to end
a[:m] # From the beginning to the m Substrings of
a[n:m:s] # From n From the beginning to m until , jumping s individual